/** * @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 int $post_ID * @param string $post_type * @param string $post_language_code * @param int|bool $trid * * @throws \InvalidArgumentException * @throws \UnexpectedValueException */ private function set_post_language($post_ID, $post_type, $post_language_code, $trid = false) { if ($post_language_code && $this->sitepress->is_translated_post_type($post_type)) { $wpml_translations = new WPML_Translations($this->sitepress); $post_element = new WPML_Post_Element($post_ID, $this->sitepress); if ($post_language_code) { $wpml_translations->set_language_code($post_element, $post_language_code); } if ($trid) { $wpml_translations->set_trid($post_element, $trid); } } }
/** * @param int $trid * @param string $el_type Use comment, post, page, {custom post time name}, nav_menu, nav_menu_item, category, post_tag, etc. (prefixed with 'post_', 'tax_', or nothing for 'comment') * @param bool $skip_empty * @param bool $all_statuses * @param bool $skip_cache * @param bool $skip_recursions * * @return array|bool|mixed */ function get_element_translations($trid, $el_type = 'post_post', $skip_empty = false, $all_statuses = false, $skip_cache = false, $skip_recursions = false) { $wpml_translations = new WPML_Translations($this); $wpml_translations->skip_empty = $skip_empty; $wpml_translations->all_statuses = $all_statuses; $wpml_translations->skip_cache = $skip_cache; $wpml_translations->skip_recursions = $skip_recursions; return $wpml_translations->get_translations($trid, $el_type); }