Esempio n. 1
0
 protected function getItems($tax, $args = [])
 {
     $items = [];
     $defaults = ['child_of' => 0, 'exclude' => '', 'hide_empty' => false, 'hierarchical' => 1, 'include' => '', 'include_last_update_time' => false, 'order' => 'ASC', 'orderby' => 'name', 'pad_counts' => false];
     $args = wp_parse_args($args, $defaults);
     $terms = get_terms($tax->name, $args);
     if (empty($terms) || is_wp_error($terms)) {
         $items[] = ['name' => '', 'label' => 'No items', 'disabled' => true];
     } else {
         $walker = new AssignmentsWalker();
         $new_terms = [];
         foreach ($terms as $new_term) {
             $new_term->id = $new_term->term_id;
             $new_term->parent_id = $new_term->parent;
             $new_terms[] = $new_term;
         }
         $terms = $walker->walk($new_terms, 0);
         foreach ($terms as $term) {
             $items[] = ['name' => $term->term_id, 'label' => $term->level > 0 ? str_repeat('—', max(0, $term->level)) . ' ' . $term->name : $term->name, 'disabled' => false];
         }
     }
     return apply_filters('g5_assignments_' . $this->type . '_' . $tax->name . '_taxonomy_list_items', $items, $tax, $this->type);
 }
Esempio n. 2
0
 protected function getItems($menu)
 {
     $items = [];
     // Get all items for the current menu
     if ($menu && !is_wp_error($menu)) {
         $menu_items = wp_get_nav_menu_items($menu->term_id);
     }
     // Check if the menu is not empty
     if (!$menu_items) {
         $items[] = ['name' => '', 'label' => 'No items', 'disabled' => true];
     } else {
         $walker = new AssignmentsWalker();
         $new_menu_items = [];
         foreach ($menu_items as $new_menu_item) {
             $new_menu_item->id = $new_menu_item->ID;
             $new_menu_item->parent_id = empty($new_menu_item->menu_item_parent) ? get_post_meta($new_menu_item->ID, '_menu_item_menu_item_parent', true) : $new_menu_item->menu_item_parent;
             $new_menu_items[] = $new_menu_item;
         }
         $menu_items = $walker->walk($new_menu_items, 0);
         foreach ($menu_items as $menu_item) {
             $items[] = ['name' => $menu_item->ID, 'label' => $menu_item->level > 0 ? str_repeat('—', max(0, $menu_item->level)) . ' ' . $menu_item->title : $menu_item->title, 'disabled' => false];
         }
     }
     return apply_filters('g5_assignments_' . $menu->slug . '_menu_list_items', $items, $menu->slug, $this->type);
 }