Exemplo n.º 1
0
 /**
  * @param integer   $post_id
  * @param SitePress $sitepress
  *
  * @return null|string
  */
 protected function get_save_post_lang($post_id, $sitepress)
 {
     $language_code = isset($post_vars['icl_post_language']) ? $post_vars['icl_post_language'] : null;
     $language_code = $language_code ? $language_code : filter_input(INPUT_GET, 'lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     $language_code = $language_code ? $language_code : parent::get_save_post_lang($post_id, $sitepress);
     return $language_code;
 }
Exemplo n.º 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;
 }
 /**
  * @param string[] $allowed_langs
  * @param int      $element_id
  * @param string   $element_type_prefix
  *
  * @return string[]
  */
 public function filter_target_langs($allowed_langs, $element_id, $element_type_prefix)
 {
     if (TranslationProxy_Basket::anywhere_in_basket($element_id, $element_type_prefix)) {
         $allowed_langs = array();
     } elseif ($element_type_prefix === 'post') {
         if ((bool) $this->post_translations->get_element_lang_code($element_id) === true) {
             $allowed_langs = array_fill_keys($allowed_langs, 1);
             $translations = $this->tm_records->icl_translations_by_element_id_and_type_prefix($element_id, 'post')->translations();
             foreach ($translations as $lang_code => $element) {
                 if (isset($allowed_langs[$lang_code]) && ($element->element_id() && !$element->source_language_code() || $this->tm_status->is_in_active_job($element_id, $lang_code, 'post'))) {
                     unset($allowed_langs[$lang_code]);
                 }
             }
             $allowed_langs = array_keys($allowed_langs);
         }
     }
     return $allowed_langs;
 }
 /**
  * @param integer   $post_id
  * @param SitePress $sitepress
  *
  * @return null|string
  */
 public function get_save_post_lang($post_id, $sitepress)
 {
     $language_code = filter_var(isset($_POST['icl_post_language']) ? $_POST['icl_post_language'] : '', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     $language_code = $language_code ? $language_code : filter_input(INPUT_GET, 'lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     return $language_code ? $language_code : parent::get_save_post_lang($post_id, $sitepress);
 }