function get_element_language_details($el_id, $el_type = 'post_post') { $details = false; if ($el_id) { if (strpos($el_type, 'post_') === 0) { global $wpml_post_translations; $details = $wpml_post_translations->get_element_language_details($el_id, OBJECT); } if (strpos($el_type, 'tax_') === 0) { /** @var WPML_Term_Translation $wpml_term_translations */ global $wpml_term_translations; $details = $wpml_term_translations->get_element_language_details($el_id, OBJECT); } if (!$details) { $cache_key = $el_id . ':' . $el_type; $cache_group = 'element_language_details'; $cached_details = wp_cache_get($cache_key, $cache_group); if ($cached_details) { return $cached_details; } if (isset($this->icl_translations_cache) && $this->icl_translations_cache->has_key($el_id . $el_type)) { return $this->icl_translations_cache->get($el_id . $el_type); } $details_query = "\n\t\t\t\tSELECT trid, language_code, source_language_code\n\t\t\t\tFROM {$this->wpdb->prefix}icl_translations\n\t\t\t\tWHERE element_id=%d AND element_type=%s\n\t\t\t\t"; $details_prepare = $this->wpdb->prepare($details_query, array($el_id, $el_type)); $details = $this->wpdb->get_row($details_prepare); if (isset($this->icl_translations_cache)) { $this->icl_translations_cache->set($el_id . $el_type, $details); } wp_cache_add($cache_key, $details, $cache_group); } } return $details; }
function get_element_language_details($el_id, $el_type = 'post_post') { global $wpdb; static $pre_load_done = false; if (!$pre_load_done && !ICL_DISABLE_CACHE) { // search previous queries for a group of posts foreach ($this->queries as $query) { $pos = strstr($query, 'post_id IN ('); if ($pos !== FALSE) { $group = substr($pos, 10); $group = substr($group, 0, strpos($group, ')') + 1); $query = "SELECT element_id, trid, language_code, source_language_code\n FROM {$wpdb->prefix}icl_translations\n WHERE element_id IN {$group} AND element_type='{$el_type}'"; $ret = $wpdb->get_results($query); foreach ($ret as $details) { if (isset($this->icl_translations_cache)) { $this->icl_translations_cache->set($details->element_id . $el_type, $details); } } // get the taxonomy for the posts for later use // categories first $query = "SELECT DISTINCT(tr.term_taxonomy_id), tt.term_id, tt.taxonomy, icl.trid, icl.language_code, icl.source_language_code\n FROM {$wpdb->prefix}term_relationships as tr\n LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt\n ON tr.term_taxonomy_id = tt.term_taxonomy_id\n LEFT JOIN {$wpdb->prefix}icl_translations as icl ON tr.term_taxonomy_id = icl.element_id\n WHERE tr.object_id IN {$group}\n AND (icl.element_type='tax_category' and tt.taxonomy='category')\n "; $query .= "UNION\n "; $query .= "SELECT DISTINCT(tr.term_taxonomy_id), tt.term_id, tt.taxonomy, icl.trid, icl.language_code, icl.source_language_code\n FROM {$wpdb->prefix}term_relationships as tr\n LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt\n ON tr.term_taxonomy_id = tt.term_taxonomy_id\n LEFT JOIN {$wpdb->prefix}icl_translations as icl ON tr.term_taxonomy_id = icl.element_id\n WHERE tr.object_id IN {$group}\n AND (icl.element_type='tax_post_tag' and tt.taxonomy='post_tag')"; global $wp_taxonomies; $custom_taxonomies = array_diff(array_keys($wp_taxonomies), array('post_tag', 'category', 'link_category')); if (!empty($custom_taxonomies)) { foreach ($custom_taxonomies as $tax) { $query .= " UNION\n SELECT DISTINCT(tr.term_taxonomy_id), tt.term_id, tt.taxonomy, icl.trid, icl.language_code, icl.source_language_code\n FROM {$wpdb->prefix}term_relationships as tr\n LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt\n ON tr.term_taxonomy_id = tt.term_taxonomy_id\n LEFT JOIN {$wpdb->prefix}icl_translations as icl ON tr.term_taxonomy_id = icl.element_id\n WHERE tr.object_id IN {$group}\n AND (icl.element_type='tax_{$tax}' and tt.taxonomy='{$tax}')"; } } $ret = $wpdb->get_results($query); foreach ($ret as $details) { // save language details $lang_details = new stdClass(); $lang_details->trid = $details->trid; $lang_details->language_code = $details->language_code; $lang_details->source_language_code = $details->source_language_code; if (isset($this->icl_translations_cache)) { $this->icl_translations_cache->set($details->term_taxonomy_id . 'tax_' . $details->taxonomy, $lang_details); // save the term taxonomy $this->icl_term_taxonomy_cache->set('category_' . $details->term_id, $details->term_taxonomy_id); } } break; } } $pre_load_done = true; } if (isset($this->icl_translations_cache) && $this->icl_translations_cache->has_key($el_id . $el_type)) { return $this->icl_translations_cache->get($el_id . $el_type); } $details_prepared_sql = $wpdb->prepare("\n SELECT trid, language_code, source_language_code\n FROM {$wpdb->prefix}icl_translations\n WHERE element_id=%d AND element_type=%s", array($el_id, $el_type)); $details = $wpdb->get_row($details_prepared_sql); if (isset($this->icl_translations_cache)) { $this->icl_translations_cache->set($el_id . $el_type, $details); } return $details; }
function get_element_language_details($el_id, $el_type = 'post_post') { global $wpdb; $cache_key = $el_id . ':' . $el_type; $cache_group = 'element_language_details'; $cached_details = wp_cache_get($cache_key, $cache_group); if ($cached_details) { return $cached_details; } if (isset($this->icl_translations_cache) && $this->icl_translations_cache->has_key($el_id . $el_type)) { return $this->icl_translations_cache->get($el_id . $el_type); } $details_prepared_sql = $wpdb->prepare("\r\n\t\t\tSELECT trid, language_code, source_language_code\r\n\t\t\tFROM {$wpdb->prefix}icl_translations\r\n\t\t\tWHERE element_id=%d AND element_type=%s", array($el_id, $el_type)); $details = $wpdb->get_row($details_prepared_sql); if (isset($this->icl_translations_cache)) { $this->icl_translations_cache->set($el_id . $el_type, $details); } wp_cache_add($cache_key, $details, $cache_group); return $details; }