Ejemplo n.º 1
0
 /**
  * Add a link to a taxonomy archive.
  *
  * @param object $lang A Babble language object for this link
  * @return void
  **/
 protected function add_taxonomy_archive_link($lang)
 {
     $classes = array();
     $queried_object = get_queried_object();
     if (!bbl_is_translated_taxonomy($queried_object->taxonomy)) {
         $this->add_arbitrary_link($lang);
         return;
     } elseif (isset($this->translations[$lang->code]->term_id)) {
         // Translation exists
         bbl_switch_to_lang($lang->code);
         $href = get_term_link($this->translations[$lang->code], bbl_get_base_taxonomy($queried_object->taxonomy));
         bbl_restore_lang();
         $title = sprintf(__('Switch to %s', 'babble'), $lang->display_name);
         $classes[] = 'bbl-existing';
         $classes[] = 'bbl-existing-term';
     } else {
         // Translation does not exist
         // Generate a URL to create the translation
         $default_term = $this->translations[bbl_get_default_lang_code()];
         $href = bbl_get_new_term_translation_url($default_term->term_id, $lang->code, $default_term->taxonomy);
         $title = sprintf(__('Create for %s', 'babble'), $lang->display_name);
         $classes[] = 'bbl-add';
         $classes[] = 'bbl-add-term';
     }
     $href = apply_filters('bbl_switch_taxonomy_archive_link', $href, $lang, $this->translations);
     $classes[] = "bbl-lang-{$lang->code} bbl-lang-{$lang->url_prefix}";
     $classes[] = 'bbl-lang';
     $classes[] = 'bbl-term';
     if ($lang == bbl_get_current_lang_code()) {
         $classes[] = 'bbl-active';
     }
     $this->links[$lang->code] = array('classes' => $classes, 'href' => $href, 'id' => $lang->url_prefix, 'meta' => array('class' => strtolower(join(' ', array_unique($classes)))), 'title' => $title, 'lang' => $lang);
 }
 public function get_post_terms_to_translate($post_id, $lang_code)
 {
     $post = get_post($post_id);
     $taxos = get_object_taxonomies($post->post_type);
     $trans_terms = array();
     foreach ($taxos as $key => $taxo) {
         if (!bbl_is_translated_taxonomy($taxo)) {
             continue;
         }
         $terms = get_the_terms($post, $taxo);
         if (empty($terms)) {
             continue;
         }
         foreach ($terms as $term) {
             $trans = bbl_get_term_translations($term->term_id, $term->taxonomy);
             if (!isset($trans[$lang_code])) {
                 $trans_terms[$taxo][$term->term_id] = $term;
             }
         }
     }
     return $trans_terms;
 }