/**
  * @param WP_Query $wp_query
  * @param WP_Query $_wp_query_back
  * @param WP_Query $saved_query
  *
  * @return array
  */
 public function get_ls_translations($wp_query, $_wp_query_back, $saved_query)
 {
     list($taxonomy, $term_id) = $this->extract_tax_archive_data($wp_query);
     if ($taxonomy && $term_id) {
         if ($this->sitepress->is_translated_taxonomy($taxonomy)) {
             $icl_taxonomy = 'tax_' . $taxonomy;
             $trid = $this->term_translation->trid_from_tax_and_id($term_id, $taxonomy);
             $translations = $this->sitepress->get_element_translations($trid, $icl_taxonomy, false);
         } else {
             $translations[$this->sitepress->get_current_language()] = (object) array('translation_id' => 0, 'language_code' => $this->sitepress->get_default_language(), 'original' => 1, 'name' => $taxonomy, 'term_id' => $term_id);
         }
     } elseif ($wp_query->is_archive() && !empty($wp_query->posts)) {
         $translations = array();
     } elseif ($wp_query->is_attachment()) {
         $trid = $this->post_translation->get_element_trid($wp_query->get_queried_object_id());
         $translations = $this->sitepress->get_element_translations($trid, 'post_attachment');
     } elseif ($wp_query->is_page() || 'page' === $this->sitepress->get_wp_api()->get_option('show_on_front') && (isset($saved_query->queried_object_id) && $saved_query->queried_object_id == $this->sitepress->get_wp_api()->get_option('page_on_front') || isset($saved_query->queried_object_id) && $saved_query->queried_object_id == $this->sitepress->get_wp_api()->get_option('page_for_posts'))) {
         $trid = $this->sitepress->get_element_trid($wp_query->get_queried_object_id(), 'post_page');
         $translations = $this->sitepress->get_element_translations($trid, 'post_page');
     } elseif ($wp_query->is_singular() && !empty($wp_query->posts) || isset($_wp_query_back->query['name']) && isset($_wp_query_back->query['post_type']) || isset($_wp_query_back->query['p'])) {
         $pid = !empty($saved_query->post->ID) ? $saved_query->post->ID : (!empty($saved_query->query['p']) ? $saved_query->query['p'] : 0);
         $trid = $this->post_translation->get_element_trid($pid);
         $post_type = get_post_type($pid);
         $translations = $this->sitepress->get_element_translations($trid, 'post_' . $post_type);
     } else {
         $wp_query->is_singular = false;
         $wp_query->is_archive = false;
         $wp_query->is_category = false;
         $wp_query->is_404 = true;
         $translations = null;
     }
     $translations = apply_filters('wpml_get_ls_translations', $translations, $wp_query);
     return array($translations, $wp_query);
 }
Exemple #2
0
 function get_element_language_details($el_id, $el_type = 'post_post')
 {
     $details = false;
     if ($el_id) {
         if (strpos($el_type, 'post_') === 0) {
             $details = $this->post_translation->get_element_language_details($el_id, OBJECT);
         }
         if (strpos($el_type, 'tax_') === 0) {
             $details = $this->term_translation->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;
 }
 /**
  * @return string|null
  */
 public function source_language_code()
 {
     $lang = $this->post_translations->get_source_lang_from_translation_id($this->translation_id);
     $lang = $lang['found'] ? $lang : $this->term_translations->get_source_lang_from_translation_id($this->translation_id);
     $lang = $lang['found'] ? $lang['code'] : $this->select_field('source_language_code');
     return $lang;
 }