/** * Fetch the post of the correct language. * * @since 2.1.0 * * @param $post_id Post ID */ function tptn_object_id_cur_lang($post_id) { $return_original_if_missing = false; /** * Filter to modify if the original language ID is returned. * * @since 2.2.3 * * @param bool $return_original_if_missing * @param int $post_id Post ID */ $return_original_if_missing = apply_filters('tptn_wpml_return_original', $return_original_if_missing, $post_id); if (function_exists('pll_get_post')) { $post_id = pll_get_post($post_id); } elseif (function_exists('wpml_object_id_filter')) { $post_id = wpml_object_id_filter($post_id, 'any', $return_original_if_missing); } elseif (function_exists('icl_object_id')) { $post_id = icl_object_id($post_id, 'any', $return_original_if_missing); } /** * Filters object ID for current language (WPML). * * @since 2.1.0 * * @param int $post_id Post ID */ return apply_filters('tptn_object_id_cur_lang', $post_id); }
/** * Get the id of the current translation of the post/custom type * * @since 2.0.0 * @author Andrea Frascaspata <*****@*****.**> */ function yit_wpml_get_translated_id($id, $post_type) { if (function_exists('wpml_object_id_filter')) { $id = wpml_object_id_filter($id, $post_type, true); } return $id; }
/** * Retrieve available translations * * @param array $object Details of current post. * @param string $field_name Name of field. * @param WP_REST_Request $request Current request * * @return mixed */ function wpmlretapi_slug_get_translations($object, $field_name, $request) { global $sitepress; $languages = apply_filters('wpml_active_languages', null); $translations = []; foreach ($languages as $language) { $post_id = wpml_object_id_filter($object['id'], 'post', false, $language['language_code']); if ($post_id === null || $post_id == $object['id']) { continue; } $thisPost = get_post($post_id); $href = apply_filters('WPML_filter_link', $language['url'], $language); if (strpos($href, '?') !== false) { $href = str_replace('?', '/' . $thisPost->post_name . '/?', $href); } else { if (substr($href, -1) !== '/') { $href .= '/'; } $href .= $thisPost->post_name . '/'; } $translations[] = array('locale' => $language['default_locale'], 'id' => $thisPost->ID, 'post_title' => $thisPost->post_title, 'href' => $href); } return $translations; }
/** * Get current layered link * * @param $term_id The term id * @param $taxonomy The taxonomy name * * @return string The new term_id * * @since 1.4 * @author Andrea Grillo <*****@*****.**> */ function yit_wcan_localize_terms($term_id, $taxonomy) { /* === WPML Support === */ global $sitepress; if (!empty($sitepress) && function_exists('wpml_object_id_filter')) { $term_id = wpml_object_id_filter($term_id, $taxonomy, true, $sitepress->get_default_language()); } return $term_id; }
/** * Retrieve translated page id, if wpml is installed * * @param $id int Original page id * @return int Translation id * @since 1.0.0 */ function yith_wcwl_object_id($id) { if (function_exists('wpml_object_id_filter')) { return wpml_object_id_filter($id, 'page', true); } elseif (function_exists('icl_object_id')) { return icl_object_id($id, 'page', true); } else { return $id; } }
/** * @since unknown * @deprecated 3.2 use 'wpml_object_id' filter instead. * * @param $element_id * @param string $element_type * @param bool $return_original_if_missing * @param null|string $ulanguage_code * * @return null|int */ function icl_object_id($element_id, $element_type = 'post', $return_original_if_missing = false, $ulanguage_code = null) { return wpml_object_id_filter($element_id, $element_type, $return_original_if_missing, $ulanguage_code); }
public function get_wpml_parent_id($product_id) { global $sitepress; if (isset($sitepress)) { $default_language = $sitepress->get_default_language(); if (function_exists('icl_object_id')) { $product_id = icl_object_id($product_id, 'product', true, $default_language); } else { if (function_exists('wpml_object_id_filter')) { $product_id = wpml_object_id_filter($product_id, 'product', true, $default_language); } } } return $product_id; }
/** * Vrátí buď požadované originální nebo "přeložené" ID pro zadaný post type * (pozn.: dle aktuálního jazyka + zavislé na pluginu WPML) * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @param string $name * @param string $postType * @return string|null */ public function getOptionTranslateId($name, $postType) { $value = $this->getOption($name); if (defined("ICL_LANGUAGE_CODE")) { if (is_array($value)) { $ids = array(); foreach ($value as $id) { array_push($ids, wpml_object_id_filter($id, $postType, true, ICL_LANGUAGE_CODE)); } return $ids; } else { $value = wpml_object_id_filter($value, $postType, true, ICL_LANGUAGE_CODE); } } return $value; }
/** * Populate the compare product list */ public function populate_products_list() { global $sitepress; /** * WPML Support */ $lang = isset($_REQUEST['lang']) ? $_REQUEST['lang'] : false; // get cookie val $the_list = isset($_COOKIE[$this->cookie_name]) ? json_decode($_COOKIE[$this->cookie_name]) : array(); // switch lang for WPML if (defined('ICL_LANGUAGE_CODE') && $lang && isset($sitepress)) { $sitepress->switch_lang($lang, true); } foreach ($the_list as $product_id) { if (function_exists('wpml_object_id_filter')) { $product_id_translated = wpml_object_id_filter($product_id, 'product', false); // get all product of current lang if ($product_id_translated !== $product_id) { continue; } } // check for deleted|private products $product = wc_get_product($product_id); if (!$product || $product->post->post_status !== 'publish') { continue; } $this->products_list[] = $product_id; } }
/** * Get id of post translation in current language * * @param int $element_id * @param string $element_type * @param bool $return_original_if_missing * @param null|string $ulanguage_code * * @return int the translation id * @since 2.0.0 * @author Antonio La Rocca <*****@*****.**> */ function yit_wpml_object_id($element_id, $element_type = 'post', $return_original_if_missing = false, $ulanguage_code = null) { if (function_exists('wpml_object_id_filter')) { return wpml_object_id_filter($element_id, $element_type, $return_original_if_missing, $ulanguage_code); } elseif (function_exists('icl_object_id')) { return icl_object_id($element_id, $element_type, $return_original_if_missing, $ulanguage_code); } else { return $element_id; } }
/** * Takes a post id, checks if the current language isn't the default language and returns a translated post id if it exists, used to switch our overriding pages or post types * @param int $post_id * @return int */ public static function get_translated_post_id($post_id, $post_type) { if (function_exists('wpml_object_id_filter')) { return wpml_object_id_filter($post_id, $post_type); } //3.2 compatible return icl_object_id($post_id, $post_type); // <3.2 compatible }