wp_nav_menu_item_taxonomy_meta_box

Displays a meta box for a taxonomy menu item.

Description

wp_nav_menu_item_taxonomy_meta_box( (string) $object, (array) $box ); 

Parameters (2)

0. $object (string)
The object.
1. $box (array)
Taxonomy menu item meta box arguments.

Options

  • id (string) => ''

    Meta box id attribute.

  • title (string) => ''

    Meta box title.

  • callback (string) => ''

    Meta box display callback.

array(

    /**
     * Meta box 'id' attribute.
     *
     * @type string
     * @default ''
     */
    'id' => '',

    /**
     * Meta box title.
     *
     * @type string
     * @default ''
     */
    'title' => '',

    /**
     * Meta box display callback.
     *
     * @type string
     * @default ''
     */
    'callback' => ''
);        


Usage

  1. if ( !function_exists( 'wp_nav_menu_item_taxonomy_meta_box' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/nav-menu.php'; 
  3.  
  4. // The object. 
  5. $object = ''; 
  6.  
  7. // Taxonomy menu item meta box arguments. 
  8. $box = array( 
  9. 'id' => '', 
  10. 'title' => '', 
  11. 'callback' => '' 
  12. ); 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = wp_nav_menu_item_taxonomy_meta_box($object, $box); 
  16.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/nav-menu.php  
  1. function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) { 
  2. global $nav_menu_selected_id; 
  3. $taxonomy_name = $box['args']->name; 
  4.  
  5. // Paginate browsing for large numbers of objects. 
  6. $per_page = 50; 
  7. $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; 
  8. $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; 
  9.  
  10. $args = array( 
  11. 'child_of' => 0,  
  12. 'exclude' => '',  
  13. 'hide_empty' => false,  
  14. 'hierarchical' => 1,  
  15. 'include' => '',  
  16. 'number' => $per_page,  
  17. 'offset' => $offset,  
  18. 'order' => 'ASC',  
  19. 'orderby' => 'name',  
  20. 'pad_counts' => false,  
  21. ); 
  22.  
  23. $terms = get_terms( $taxonomy_name, $args ); 
  24.  
  25. if ( ! $terms || is_wp_error($terms) ) { 
  26. echo '<p>' . __( 'No items.' ) . '</p>'; 
  27. return; 
  28.  
  29. $num_pages = ceil( wp_count_terms( $taxonomy_name , array_merge( $args, array('number' => '', 'offset' => '') ) ) / $per_page ); 
  30.  
  31. $page_links = paginate_links( array( 
  32. 'base' => add_query_arg
  33. array( 
  34. $taxonomy_name . '-tab' => 'all',  
  35. 'paged' => '%#%',  
  36. 'item-type' => 'taxonomy',  
  37. 'item-object' => $taxonomy_name,  
  38. ),  
  39. 'format' => '',  
  40. 'prev_text' => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '«' ) . '</span>',  
  41. 'next_text' => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '»' ) . '</span>',  
  42. 'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',  
  43. 'total' => $num_pages,  
  44. 'current' => $pagenum 
  45. )); 
  46.  
  47. $db_fields = false; 
  48. if ( is_taxonomy_hierarchical( $taxonomy_name ) ) { 
  49. $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' ); 
  50.  
  51. $walker = new Walker_Nav_Menu_Checklist( $db_fields ); 
  52.  
  53. $current_tab = 'most-used'; 
  54. if ( isset( $_REQUEST[$taxonomy_name . '-tab'] ) && in_array( $_REQUEST[$taxonomy_name . '-tab'], array('all', 'most-used', 'search') ) ) { 
  55. $current_tab = $_REQUEST[$taxonomy_name . '-tab']; 
  56.  
  57. if ( ! empty( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) { 
  58. $current_tab = 'search'; 
  59.  
  60. $removed_args = array( 
  61. 'action',  
  62. 'customlink-tab',  
  63. 'edit-menu-item',  
  64. 'menu-item',  
  65. 'page-tab',  
  66. '_wpnonce',  
  67. ); 
  68.  
  69. ?> 
  70. <div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv"> 
  71. <ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs"> 
  72. <li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>> 
  73. <a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-pop" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'most-used', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-pop"> 
  74. <?php _e( 'Most Used' ); ?> 
  75. </a> 
  76. </li> 
  77. <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>> 
  78. <a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-all" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-all"> 
  79. <?php _e( 'View All' ); ?> 
  80. </a> 
  81. </li> 
  82. <li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>> 
  83. <a class="nav-tab-link" data-type="tabs-panel-search-taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>"> 
  84. <?php _e( 'Search' ); ?> 
  85. </a> 
  86. </li> 
  87. </ul><!-- .taxonomy-tabs --> 
  88.  
  89. <div id="tabs-panel-<?php echo $taxonomy_name; ?>-pop" class="tabs-panel <?php 
  90. echo ( 'most-used' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 
  91. ?>"> 
  92. <ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" > 
  93. <?php 
  94. $popular_terms = get_terms( $taxonomy_name, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); 
  95. $args[walker] = $walker; 
  96. echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $popular_terms), 0, (object) $args ); 
  97. ?> 
  98. </ul> 
  99. </div><!-- /.tabs-panel --> 
  100.  
  101. <div id="tabs-panel-<?php echo $taxonomy_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php 
  102. echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 
  103. ?>"> 
  104. <?php if ( ! empty( $page_links ) ) : ?> 
  105. <div class="add-menu-item-pagelinks"> 
  106. <?php echo $page_links; ?> 
  107. </div> 
  108. <?php endif; ?> 
  109. <ul id="<?php echo $taxonomy_name; ?>checklist" data-wp-lists="list:<?php echo $taxonomy_name?>" class="categorychecklist form-no-clear"> 
  110. <?php 
  111. $args[walker] = $walker; 
  112. echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $terms), 0, (object) $args ); 
  113. ?> 
  114. </ul> 
  115. <?php if ( ! empty( $page_links ) ) : ?> 
  116. <div class="add-menu-item-pagelinks"> 
  117. <?php echo $page_links; ?> 
  118. </div> 
  119. <?php endif; ?> 
  120. </div><!-- /.tabs-panel --> 
  121.  
  122. <div class="tabs-panel <?php 
  123. echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); 
  124. ?>" id="tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>"> 
  125. <?php 
  126. if ( isset( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) { 
  127. $searched = esc_attr( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ); 
  128. $search_results = get_terms( $taxonomy_name, array( 'name__like' => $searched, 'fields' => 'all', 'orderby' => 'count', 'order' => 'DESC', 'hierarchical' => false ) ); 
  129. } else { 
  130. $searched = ''; 
  131. $search_results = array(); 
  132. ?> 
  133. <p class="quick-search-wrap"> 
  134. <label for="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label> 
  135. <input type="search" class="quick-search" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" id="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" /> 
  136. <span class="spinner"></span> 
  137. <?php submit_button( __( 'Search' ), 'small quick-search-submit hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?> 
  138. </p> 
  139.  
  140. <ul id="<?php echo $taxonomy_name; ?>-search-checklist" data-wp-lists="list:<?php echo $taxonomy_name?>" class="categorychecklist form-no-clear"> 
  141. <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?> 
  142. <?php 
  143. $args[walker] = $walker; 
  144. echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args ); 
  145. ?> 
  146. <?php elseif ( is_wp_error( $search_results ) ) : ?> 
  147. <li><?php echo $search_results->get_error_message(); ?></li> 
  148. <?php elseif ( ! empty( $searched ) ) : ?> 
  149. <li><?php _e('No results found.'); ?></li> 
  150. <?php endif; ?> 
  151. </ul> 
  152. </div><!-- /.tabs-panel --> 
  153.  
  154. <p class="button-controls wp-clearfix"> 
  155. <span class="list-controls"> 
  156. <a href="<?php 
  157. echo esc_url(add_query_arg( 
  158. array( 
  159. $taxonomy_name . '-tab' => 'all',  
  160. 'selectall' => 1,  
  161. ),  
  162. remove_query_arg($removed_args) 
  163. )); 
  164. ?>#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all aria-button-if-js"><?php _e( 'Select All' ); ?></a> 
  165. </span> 
  166.  
  167. <span class="add-to-menu"> 
  168. <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-taxonomy-menu-item" id="<?php echo esc_attr( 'submit-taxonomy-' . $taxonomy_name ); ?>" /> 
  169. <span class="spinner"></span> 
  170. </span> 
  171. </p> 
  172.  
  173. </div><!-- /.taxonomydiv --> 
  174. <?php