/** * @param string|bool $canonical_url * @param WP_Post $post * * @return string|bool */ public function get_canonical_url($canonical_url, $post) { if ($post && $this->sitepress->get_wp_api()->is_front_end()) { $post_element = new WPML_Post_Element($post->ID, $this->sitepress); if (!$post_element->is_translatable()) { $canonical_url = $this->sitepress->convert_url($canonical_url, $this->sitepress->get_default_language()); } else { $wpml_translations = new WPML_Translations($this->sitepress); if ($wpml_translations->is_a_duplicate_of($post_element)) { $canonical_url = (string) $this->get_canonical_of_duplicate($post_element); } } } return $canonical_url; }
/** * @param string $link * @param int|WP_Post $post * * @return bool|mixed|string */ public function permalink_filter($link, $post) { if (!$post) { return $link; } /** @var int $post */ if (is_object($post)) { $post = $post->ID; } $canonical_url = $this->canonicals->permalink_filter($link, $post); if ($canonical_url) { return $canonical_url; } $post_element = new WPML_Post_Element($post, $this->sitepress); if ($post_element->is_translatable()) { $link = $this->get_translated_permalink($link, $post, $post_element); } return $link; }