d($id, $post_type) { return \pll_get_post($id, $this->getDefaultLanguage()); } // Documented in AbstractSyncPlugin public function getOriginalTermId($id, $taxonomy) { return \pll_get_term($id, $this->getDefaultLanguage()); } // Documented in AbstractLanguagePlugin public function getPostTranslationIds($id, $post_type) { return \pll_get_post_translations($id); } // Documented in AbstractLanguagePlugin public function getTaxonomyTranslationIds($id, $taxonomy) { return \pll_get_term_translations($id); } // Documented in AbstractSyncPlugin public function getCurrentPostId($id, $post_type, $locale = null) { $result = \pll_get_post($id, $locale === null ? $this->getCurrentLanguage() : $locale); return empty($result) ? $id : $result; } // Documented in AbstractSyncPlugin public function getCurrentTermId($id, $taxonomy, $locale = null) { $result = \pll_get_term($id, $locale === null ? $this->getCurrentLanguage() : $locale); return empty($result) ? $id : $result; } /** * Disable sync mechanism of our language plugin as it is handled by `Sync.php`. * * @param Sync $sync */ public function disableCopyAndSync($sync) { if ($this->disabledCopyAndSync) { // Do not do this twice. return; } $this->disabledCopyAndSync = \true; \add_filter('pll_copy_taxonomies', function ($taxonomies) use($sync) { foreach (\array_keys($sync->getTaxonomies()) as $taxToRemove) { if (isset($taxonomies[$taxToRemove])) { unset($taxonomies[$taxToRemove]); } } return $taxonomies; }); \add_filter('pll_copy_post_metas', function ($keys, $isSync, $from) use($sync) { $post = \get_post($from); if ($post instanceof WP_Post && \in_array($post->post_type, \array_keys($sync->getPostsConfiguration()), \true)) { $keys = []; } return $keys; }, 10, 3); \add_filter('pll_copy_term_metas', function ($keys, $isSync, $from) use($sync) { $term = \get_term($from); if ($term instanceof WP_Term && \in_array($term->taxonomy, \array_keys($sync->getTaxonomies()), \true)) { $keys = []; } return $keys; }, 10, 3); // WordPress 6.0 compatibility: PolyLang also introduced something like this, but due to the fact we disable // syncing of our configured taxonomies, we need to reimplement this filter. // See: https://github.com/polylang/polylang/blob/923a309fcb00cb87cef36bfbd23a0b492612f32a/include/filters.php#L434 \add_filter('term_exists_default_query_args', function ($defaults, $term, $taxonomy) use($sync) { if ($sync->isEnabled() && !isset($defaults['lang']) && \in_array($taxonomy, \array_keys($sync->getTaxonomies()), \true)) { $defaults['lang'] = ''; } return $defaults; }, 11, 3); } /** * Check if PolyLang is active. */ public static function isPresent() { // Never do anything while trying to deactivate the plugin if (isset($_GET['action'], $_GET['plugin']) && $_GET['action'] === 'deactivate' && \strpos($_GET['plugin'], 'polylang') === 0) { return \false; } return \is_plugin_active('polylang/polylang.php') || \is_plugin_active('polylang-pro/polylang.php'); } }