Ejemplo n.º 1
0
 public function getCategories()
 {
     if ($this->categories === null) {
         $terms = wp_get_post_terms($this->post->ID, 'casawp_category', array("fields" => "all"));
         $c_trans = null;
         $lang = substr(get_bloginfo('language'), 0, 2);
         foreach ($terms as $term) {
             $termSlug = $term->slug;
             $termName = $term->name;
             if ($this->categoryService->keyExists($termSlug)) {
                 $this->categories[] = $this->categoryService->getItem($termSlug);
             } else {
                 if ($this->utilityService->keyExists($termSlug)) {
                     $this->categories[] = $this->utilityService->getItem($termSlug);
                 } else {
                     $unknown_category = new \CasasoftStandards\Service\Category();
                     $unknown_category->setKey($termSlug);
                     $unknown_category->setLabel($termName);
                     if ($c_trans === null) {
                         $c_trans = maybe_unserialize(get_option('casawp_custom_category_translations'));
                         if (!$c_trans) {
                             $c_trans = array();
                         }
                     }
                     foreach ($c_trans as $key => $trans) {
                         if ($key == $termName && array_key_exists($lang, $trans)) {
                             $unknown_category->setLabel($trans[$lang]);
                         }
                     }
                     $this->categories[] = $unknown_category;
                 }
             }
         }
     }
     return $this->categories;
 }
Ejemplo n.º 2
0
 public function getCategories()
 {
     $categories = array();
     $category_terms = get_terms('casawp_category', array('hide_empty' => true));
     foreach ($category_terms as $category_term) {
         if ($this->categoryService->keyExists($category_term->slug)) {
             $categories[] = $this->categoryService->getItem($category_term->slug);
         } else {
             if ($this->utilityService->keyExists($category_term->slug)) {
                 $categories[] = $this->utilityService->getItem($category_term->slug);
             } else {
                 $unknown_category = new \CasasoftStandards\Service\Category();
                 $unknown_category->setKey($category_term->slug);
                 $unknown_category->setLabel('?' . $category_term->slug);
                 $categories[] = $unknown_category;
             }
         }
     }
     return $categories;
 }