-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from ItinerisLtd/clickup/86c11c4qp/Multilingua…
…lPress-archives-suport MultilingualPress Integration
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Itineris\PageAsPostTypeArchive\Integrations; | ||
|
||
/** | ||
* Inpsyde MultilingualPress integration. | ||
*/ | ||
|
||
final class MultilingualPress { | ||
public function __construct() | ||
{ | ||
if ( | ||
! is_plugin_active('multilingualpress/multilingualpress.php') | ||
|| ! class_exists('\Inpsyde\MultilingualPress\Framework\Api\Translation') | ||
) | ||
{ | ||
return; | ||
} | ||
|
||
add_filter( | ||
\Inpsyde\MultilingualPress\Framework\Api\Translation::FILTER_URL, | ||
[$this, 'translateMultilingualPressArchivePageUrl'], | ||
10, | ||
4, | ||
); | ||
} | ||
|
||
public static function init(): self | ||
{ | ||
return new self(); | ||
} | ||
|
||
/** | ||
* MultilingualPress Archive Page URL translation. | ||
* | ||
* @param string $remoteUrl | ||
* @param int $remoteSiteId | ||
* @param int $remoteContentId | ||
* @param \Inpsyde\MultilingualPress\Framework\Api\Translation $translation | ||
* @return string | ||
*/ | ||
public static function translateMultilingualPressArchivePageUrl( | ||
string $remoteUrl, | ||
int $remoteSiteId, | ||
int $remoteContentId, | ||
\Inpsyde\MultilingualPress\Framework\Api\Translation $translation | ||
): string { | ||
if ( | ||
! class_exists('\Inpsyde\MultilingualPress\Framework\WordpressContext') | ||
|| ! is_archive() | ||
|| \Inpsyde\MultilingualPress\Framework\WordpressContext::TYPE_POST_TYPE_ARCHIVE !== $translation->type() | ||
) { | ||
return $remoteUrl; | ||
} | ||
|
||
$postType = get_queried_post_type(); | ||
switch_to_blog($remoteSiteId); | ||
$remoteArchivePageId = get_archive_page_id($postType); | ||
if (0 !== $remoteArchivePageId) { | ||
$remoteUrl = get_permalink($remoteArchivePageId); | ||
} | ||
restore_current_blog(); | ||
|
||
return $remoteUrl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters