[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> nav-menu.php (source)

   1  <?php
   2  
   3  /**
   4   * Create HTML list of nav menu input items.
   5   *
   6   * @package WordPress
   7   * @since 3.0.0
   8   * @uses Walker_Nav_Menu
   9   */
  10  class Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
  11      /**
  12       * @see Walker_Nav_Menu::start_lvl()
  13       * @since 3.0.0
  14       *
  15       * @param string $output Passed by reference.
  16       */
  17  	function start_lvl(&$output) {}
  18  
  19      /**
  20       * @see Walker_Nav_Menu::end_lvl()
  21       * @since 3.0.0
  22       *
  23       * @param string $output Passed by reference.
  24       */
  25  	function end_lvl(&$output) {
  26      }
  27  
  28      /**
  29       * @see Walker::start_el()
  30       * @since 3.0.0
  31       *
  32       * @param string $output Passed by reference. Used to append additional content.
  33       * @param object $item Menu item data object.
  34       * @param int $depth Depth of menu item. Used for padding.
  35       * @param object $args
  36       */
  37  	function start_el(&$output, $item, $depth, $args) {
  38          global $_wp_nav_menu_max_depth;
  39          $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
  40  
  41          $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  42  
  43          ob_start();
  44          $item_id = esc_attr( $item->ID );
  45          $removed_args = array(
  46              'action',
  47              'customlink-tab',
  48              'edit-menu-item',
  49              'menu-item',
  50              'page-tab',
  51              '_wpnonce',
  52          );
  53  
  54          $original_title = '';
  55          if ( 'taxonomy' == $item->type ) {
  56              $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
  57              if ( is_wp_error( $original_title ) )
  58                  $original_title = false;
  59          } elseif ( 'post_type' == $item->type ) {
  60              $original_object = get_post( $item->object_id );
  61              $original_title = $original_object->post_title;
  62          }
  63  
  64          $classes = array(
  65              'menu-item menu-item-depth-' . $depth,
  66              'menu-item-' . esc_attr( $item->object ),
  67              'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
  68          );
  69  
  70          $title = $item->title;
  71  
  72          if ( ! empty( $item->_invalid ) ) {
  73              $classes[] = 'menu-item-invalid';
  74              /* translators: %s: title of menu item which is invalid */
  75              $title = sprintf( __( '%s (Invalid)' ), $item->title );
  76          } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
  77              $classes[] = 'pending';
  78              /* translators: %s: title of menu item in draft status */
  79              $title = sprintf( __('%s (Pending)'), $item->title );
  80          }
  81  
  82          $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
  83  
  84          $submenu_text = '';
  85          if ( 0 == $depth )
  86              $submenu_text = 'style="display: none;"';
  87  
  88          ?>
  89          <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
  90              <dl class="menu-item-bar">
  91                  <dt class="menu-item-handle">
  92                      <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span>
  93                      <span class="item-controls">
  94                          <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
  95                          <span class="item-order hide-if-js">
  96                              <a href="<?php
  97                                  echo wp_nonce_url(
  98                                      add_query_arg(
  99                                          array(
 100                                              'action' => 'move-up-menu-item',
 101                                              'menu-item' => $item_id,
 102                                          ),
 103                                          remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
 104                                      ),
 105                                      'move-menu_item'
 106                                  );
 107                              ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">&#8593;</abbr></a>
 108                              |
 109                              <a href="<?php
 110                                  echo wp_nonce_url(
 111                                      add_query_arg(
 112                                          array(
 113                                              'action' => 'move-down-menu-item',
 114                                              'menu-item' => $item_id,
 115                                          ),
 116                                          remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
 117                                      ),
 118                                      'move-menu_item'
 119                                  );
 120                              ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
 121                          </span>
 122                          <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php
 123                              echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
 124                          ?>"><?php _e( 'Edit Menu Item' ); ?></a>
 125                      </span>
 126                  </dt>
 127              </dl>
 128  
 129              <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
 130                  <?php if( 'custom' == $item->type ) : ?>
 131                      <p class="field-url description description-wide">
 132                          <label for="edit-menu-item-url-<?php echo $item_id; ?>">
 133                              <?php _e( 'URL' ); ?><br />
 134                              <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
 135                          </label>
 136                      </p>
 137                  <?php endif; ?>
 138                  <p class="description description-thin">
 139                      <label for="edit-menu-item-title-<?php echo $item_id; ?>">
 140                          <?php _e( 'Navigation Label' ); ?><br />
 141                          <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
 142                      </label>
 143                  </p>
 144                  <p class="description description-thin">
 145                      <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
 146                          <?php _e( 'Title Attribute' ); ?><br />
 147                          <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
 148                      </label>
 149                  </p>
 150                  <p class="field-link-target description">
 151                      <label for="edit-menu-item-target-<?php echo $item_id; ?>">
 152                          <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
 153                          <?php _e( 'Open link in a new window/tab' ); ?>
 154                      </label>
 155                  </p>
 156                  <p class="field-css-classes description description-thin">
 157                      <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
 158                          <?php _e( 'CSS Classes (optional)' ); ?><br />
 159                          <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
 160                      </label>
 161                  </p>
 162                  <p class="field-xfn description description-thin">
 163                      <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
 164                          <?php _e( 'Link Relationship (XFN)' ); ?><br />
 165                          <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
 166                      </label>
 167                  </p>
 168                  <p class="field-description description description-wide">
 169                      <label for="edit-menu-item-description-<?php echo $item_id; ?>">
 170                          <?php _e( 'Description' ); ?><br />
 171                          <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
 172                          <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
 173                      </label>
 174                  </p>
 175  
 176                  <p class="field-move description description-wide">
 177                      <label>
 178                          <span><?php _e( 'Move' ); ?></span>
 179                          <a href="#" class="menus-move-up"><?php _e( 'Up one' ); ?></a>
 180                          <a href="#" class="menus-move-down"><?php _e( 'Down one' ); ?></a>
 181                          <a href="#" class="menus-move-left"></a>
 182                          <a href="#" class="menus-move-right"></a>
 183                          <a href="#" class="menus-move-top"><?php _e( 'To the top' ); ?></a>
 184                      </label>
 185                  </p>
 186  
 187                  <div class="menu-item-actions description-wide submitbox">
 188                      <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
 189                          <p class="link-to-original">
 190                              <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
 191                          </p>
 192                      <?php endif; ?>
 193                      <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
 194                      echo wp_nonce_url(
 195                          add_query_arg(
 196                              array(
 197                                  'action' => 'delete-menu-item',
 198                                  'menu-item' => $item_id,
 199                              ),
 200                              admin_url( 'nav-menus.php' )
 201                          ),
 202                          'delete-menu_item_' . $item_id
 203                      ); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
 204                          ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
 205                  </div>
 206  
 207                  <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
 208                  <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
 209                  <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
 210                  <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
 211                  <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
 212                  <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
 213              </div><!-- .menu-item-settings-->
 214              <ul class="menu-item-transport"></ul>
 215          <?php
 216          $output .= ob_get_clean();
 217      }
 218  }
 219  
 220  /**
 221   * Create HTML list of nav menu input items.
 222   *
 223   * @package WordPress
 224   * @since 3.0.0
 225   * @uses Walker_Nav_Menu
 226   */
 227  class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
 228  	function __construct( $fields = false ) {
 229          if ( $fields ) {
 230              $this->db_fields = $fields;
 231          }
 232      }
 233  
 234  	function start_lvl( &$output, $depth ) {
 235          $indent = str_repeat( "\t", $depth );
 236          $output .= "\n$indent<ul class='children'>\n";
 237      }
 238  
 239  	function end_lvl( &$output, $depth ) {
 240          $indent = str_repeat( "\t", $depth );
 241          $output .= "\n$indent</ul>";
 242      }
 243  
 244      /**
 245       * @see Walker::start_el()
 246       * @since 3.0.0
 247       *
 248       * @param string $output Passed by reference. Used to append additional content.
 249       * @param object $item Menu item data object.
 250       * @param int $depth Depth of menu item. Used for padding.
 251       * @param object $args
 252       */
 253  	function start_el(&$output, $item, $depth, $args) {
 254          global $_nav_menu_placeholder;
 255  
 256          $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
 257          $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
 258          $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;
 259  
 260          $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
 261  
 262          $output .= $indent . '<li>';
 263          $output .= '<label class="menu-item-title">';
 264          $output .= '<input type="checkbox" class="menu-item-checkbox';
 265          if ( property_exists( $item, 'front_or_home' ) && $item->front_or_home ) {
 266              $title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $item->post_title );
 267              $output .= ' add-to-top';
 268          }
 269          $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> ';
 270          $output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title );
 271          $output .= '</label>';
 272  
 273          // Menu item hidden fields
 274          $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
 275          $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />';
 276          $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->menu_item_parent ) .'" />';
 277          $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />';
 278          $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />';
 279          $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />';
 280          $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
 281          $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />';
 282          $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
 283          $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
 284      }
 285  }
 286  
 287  /**
 288   * Prints the appropriate response to a menu quick search.
 289   *
 290   * @since 3.0.0
 291   *
 292   * @param array $request The unsanitized request values.
 293   */
 294  function _wp_ajax_menu_quick_search( $request = array() ) {
 295      $args = array();
 296      $type = isset( $request['type'] ) ? $request['type'] : '';
 297      $object_type = isset( $request['object_type'] ) ? $request['object_type'] : '';
 298      $query = isset( $request['q'] ) ? $request['q'] : '';
 299      $response_format = isset( $request['response-format'] ) && in_array( $request['response-format'], array( 'json', 'markup' ) ) ? $request['response-format'] : 'json';
 300  
 301      if ( 'markup' == $response_format ) {
 302          $args['walker'] = new Walker_Nav_Menu_Checklist;
 303      }
 304  
 305      if ( 'get-post-item' == $type ) {
 306          if ( post_type_exists( $object_type ) ) {
 307              if ( isset( $request['ID'] ) ) {
 308                  $object_id = (int) $request['ID'];
 309                  if ( 'markup' == $response_format ) {
 310                      echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args );
 311                  } elseif ( 'json' == $response_format ) {
 312                      $post_obj = get_post( $object_id );
 313                      echo json_encode(
 314                          array(
 315                              'ID' => $object_id,
 316                              'post_title' => get_the_title( $object_id ),
 317                              'post_type' => get_post_type( $object_id ),
 318                          )
 319                      );
 320                      echo "\n";
 321                  }
 322              }
 323          } elseif ( taxonomy_exists( $object_type ) ) {
 324              if ( isset( $request['ID'] ) ) {
 325                  $object_id = (int) $request['ID'];
 326                  if ( 'markup' == $response_format ) {
 327                      echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args );
 328                  } elseif ( 'json' == $response_format ) {
 329                      $post_obj = get_term( $object_id, $object_type );
 330                      echo json_encode(
 331                          array(
 332                              'ID' => $object_id,
 333                              'post_title' => $post_obj->name,
 334                              'post_type' => $object_type,
 335                          )
 336                      );
 337                      echo "\n";
 338                  }
 339              }
 340  
 341          }
 342  
 343      } elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) {
 344          if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) {
 345              query_posts(array(
 346                  'posts_per_page' => 10,
 347                  'post_type' => $matches[2],
 348                  's' => $query,
 349              ));
 350              if ( ! have_posts() )
 351                  return;
 352              while ( have_posts() ) {
 353                  the_post();
 354                  if ( 'markup' == $response_format ) {
 355                      $var_by_ref = get_the_ID();
 356                      echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args );
 357                  } elseif ( 'json' == $response_format ) {
 358                      echo json_encode(
 359                          array(
 360                              'ID' => get_the_ID(),
 361                              'post_title' => get_the_title(),
 362                              'post_type' => get_post_type(),
 363                          )
 364                      );
 365                      echo "\n";
 366                  }
 367              }
 368          } elseif ( 'taxonomy' == $matches[1] ) {
 369              $terms = get_terms( $matches[2], array(
 370                  'name__like' => $query,
 371                  'number' => 10,
 372              ));
 373              if ( empty( $terms ) || is_wp_error( $terms ) )
 374                  return;
 375              foreach( (array) $terms as $term ) {
 376                  if ( 'markup' == $response_format ) {
 377                      echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args );
 378                  } elseif ( 'json' == $response_format ) {
 379                      echo json_encode(
 380                          array(
 381                              'ID' => $term->term_id,
 382                              'post_title' => $term->name,
 383                              'post_type' => $matches[2],
 384                          )
 385                      );
 386                      echo "\n";
 387                  }
 388              }
 389          }
 390      }
 391  }
 392  
 393  /**
 394   * Register nav menu metaboxes and advanced menu items
 395   *
 396   * @since 3.0.0
 397   **/
 398  function wp_nav_menu_setup() {
 399      // Register meta boxes
 400      wp_nav_menu_post_type_meta_boxes();
 401      add_meta_box( 'add-custom-links', __( 'Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
 402      wp_nav_menu_taxonomy_meta_boxes();
 403  
 404      // Register advanced menu items (columns)
 405      add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
 406  
 407      // If first time editing, disable advanced items by default.
 408      if( false === get_user_option( 'managenav-menuscolumnshidden' ) ) {
 409          $user = wp_get_current_user();
 410          update_user_option($user->ID, 'managenav-menuscolumnshidden',
 411              array( 0 => 'link-target', 1 => 'css-classes', 2 => 'xfn', 3 => 'description', ),
 412              true);
 413      }
 414  }
 415  
 416  /**
 417   * Limit the amount of meta boxes to just links, pages and cats for first time users.
 418   *
 419   * @since 3.0.0
 420   **/
 421  function wp_initial_nav_menu_meta_boxes() {
 422      global $wp_meta_boxes;
 423  
 424      if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array($wp_meta_boxes) )
 425          return;
 426  
 427      $initial_meta_boxes = array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category' );
 428      $hidden_meta_boxes = array();
 429  
 430      foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) {
 431          foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) {
 432              foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) {
 433                  if ( in_array( $box['id'], $initial_meta_boxes ) ) {
 434                      unset( $box['id'] );
 435                  } else {
 436                      $hidden_meta_boxes[] = $box['id'];
 437                  }
 438              }
 439          }
 440      }
 441  
 442      $user = wp_get_current_user();
 443      update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );
 444  }
 445  
 446  /**
 447   * Creates metaboxes for any post type menu item.
 448   *
 449   * @since 3.0.0
 450   */
 451  function wp_nav_menu_post_type_meta_boxes() {
 452      $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
 453  
 454      if ( ! $post_types )
 455          return;
 456  
 457      foreach ( $post_types as $post_type ) {
 458          $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
 459          if ( $post_type ) {
 460              $id = $post_type->name;
 461              // give pages a higher priority
 462              $priority = ( 'page' == $post_type->name ? 'core' : 'default' );
 463              add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type );
 464          }
 465      }
 466  }
 467  
 468  /**
 469   * Creates metaboxes for any taxonomy menu item.
 470   *
 471   * @since 3.0.0
 472   */
 473  function wp_nav_menu_taxonomy_meta_boxes() {
 474      $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' );
 475  
 476      if ( !$taxonomies )
 477          return;
 478  
 479      foreach ( $taxonomies as $tax ) {
 480          $tax = apply_filters( 'nav_menu_meta_box_object', $tax );
 481          if ( $tax ) {
 482              $id = $tax->name;
 483              add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax );
 484          }
 485      }
 486  }
 487  
 488  /**
 489   * Displays a metabox for the nav menu theme locations.
 490   *
 491   * @since 3.0.0
 492   */
 493  function wp_nav_menu_locations_meta_box() {
 494      global $nav_menu_selected_id;
 495  
 496      if ( ! current_theme_supports( 'menus' ) ) {
 497          // We must only support widgets. Leave a message and bail.
 498          echo '<p class="howto">' . __('The current theme does not natively support menus, but you can use the &#8220;Custom Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p>';
 499          return;
 500      }
 501  
 502      $locations = get_registered_nav_menus();
 503      $menus = wp_get_nav_menus();
 504      $menu_locations = get_nav_menu_locations();
 505      $num_locations = count( array_keys($locations) );
 506  
 507      echo '<p class="howto">' . _n( 'Select a menu to use within your theme.', 'Select the menus you will use in your theme.', $num_locations ) . '</p>';
 508  
 509      foreach ( $locations as $location => $description ) {
 510          ?>
 511          <p>
 512              <label class="howto" for="locations-<?php echo $location; ?>">
 513                  <span><?php echo $description; ?></span>
 514                  <select name="menu-locations[<?php echo $location; ?>]" id="locations-<?php echo $location; ?>">
 515                      <option value="0"></option>
 516                      <?php foreach ( $menus as $menu ) : ?>
 517                      <option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?>
 518                          value="<?php echo $menu->term_id; ?>"><?php echo wp_html_excerpt( $menu->name, 40, '&hellip;' ); ?></option>
 519                      <?php endforeach; ?>
 520                  </select>
 521              </label>
 522          </p>
 523      <?php
 524      }
 525      ?>
 526      <p class="button-controls">
 527          <?php submit_button( __( 'Save' ), 'primary right', 'nav-menu-locations', false, wp_nav_menu_disabled_check( $nav_menu_selected_id ) ); ?>
 528          <span class="spinner"></span>
 529      </p>
 530      <?php
 531  }
 532  
 533  /**
 534   * Check whether to disable the Menu Locations meta box submit button
 535   *
 536   * @since 3.6.0
 537   *
 538   * @uses global $one_theme_location_no_menus to determine if no menus exist
 539   * @uses disabled() to output the disabled attribute in $other_attributes param in submit_button()
 540   *
 541   * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu
 542   * @return string Disabled attribute if at least one menu exists, false if not
 543  */
 544  function wp_nav_menu_disabled_check( $nav_menu_selected_id ) {
 545      global $one_theme_location_no_menus;
 546  
 547      if ( $one_theme_location_no_menus )
 548          return false;
 549  
 550      return disabled( $nav_menu_selected_id, 0 );
 551  }
 552  
 553  /**
 554   * Displays a metabox for the custom links menu item.
 555   *
 556   * @since 3.0.0
 557   */
 558  function wp_nav_menu_item_link_meta_box() {
 559      global $_nav_menu_placeholder, $nav_menu_selected_id;
 560  
 561      $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
 562  
 563      ?>
 564      <div class="customlinkdiv" id="customlinkdiv">
 565          <input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
 566          <p id="menu-item-url-wrap">
 567              <label class="howto" for="custom-menu-item-url">
 568                  <span><?php _e('URL'); ?></span>
 569                  <input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" />
 570              </label>
 571          </p>
 572  
 573          <p id="menu-item-name-wrap">
 574              <label class="howto" for="custom-menu-item-name">
 575                  <span><?php _e( 'Link Text' ); ?></span>
 576                  <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Menu Item'); ?>" />
 577              </label>
 578          </p>
 579  
 580          <p class="button-controls">
 581              <span class="add-to-menu">
 582                  <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" />
 583                  <span class="spinner"></span>
 584              </span>
 585          </p>
 586  
 587      </div><!-- /.customlinkdiv -->
 588      <?php
 589  }
 590  
 591  /**
 592   * Displays a metabox for a post type menu item.
 593   *
 594   * @since 3.0.0
 595   *
 596   * @param string $object Not used.
 597   * @param string $post_type The post type object.
 598   */
 599  function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) {
 600      global $_nav_menu_placeholder, $nav_menu_selected_id;
 601  
 602      $post_type_name = $post_type['args']->name;
 603  
 604      // paginate browsing for large numbers of post objects
 605      $per_page = 50;
 606      $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
 607      $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
 608  
 609      $args = array(
 610          'offset' => $offset,
 611          'order' => 'ASC',
 612          'orderby' => 'title',
 613          'posts_per_page' => $per_page,
 614          'post_type' => $post_type_name,
 615          'suppress_filters' => true,
 616          'update_post_term_cache' => false,
 617          'update_post_meta_cache' => false
 618      );
 619  
 620      if ( isset( $post_type['args']->_default_query ) )
 621          $args = array_merge($args, (array) $post_type['args']->_default_query );
 622  
 623      // @todo transient caching of these results with proper invalidation on updating of a post of this type
 624      $get_posts = new WP_Query;
 625      $posts = $get_posts->query( $args );
 626      if ( ! $get_posts->post_count ) {
 627          echo '<p>' . __( 'No items.' ) . '</p>';
 628          return;
 629      }
 630  
 631      $post_type_object = get_post_type_object($post_type_name);
 632  
 633      $num_pages = $get_posts->max_num_pages;
 634  
 635      $page_links = paginate_links( array(
 636          'base' => add_query_arg(
 637              array(
 638                  $post_type_name . '-tab' => 'all',
 639                  'paged' => '%#%',
 640                  'item-type' => 'post_type',
 641                  'item-object' => $post_type_name,
 642              )
 643          ),
 644          'format' => '',
 645          'prev_text' => __('&laquo;'),
 646          'next_text' => __('&raquo;'),
 647          'total' => $num_pages,
 648          'current' => $pagenum
 649      ));
 650  
 651      if ( !$posts )
 652          $error = '<li id="error">'. $post_type['args']->labels->not_found .'</li>';
 653  
 654      $db_fields = false;
 655      if ( is_post_type_hierarchical( $post_type_name ) ) {
 656          $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' );
 657      }
 658  
 659      $walker = new Walker_Nav_Menu_Checklist( $db_fields );
 660  
 661      $current_tab = 'most-recent';
 662      if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) {
 663          $current_tab = $_REQUEST[$post_type_name . '-tab'];
 664      }
 665  
 666      if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
 667          $current_tab = 'search';
 668      }
 669  
 670      $removed_args = array(
 671          'action',
 672          'customlink-tab',
 673          'edit-menu-item',
 674          'menu-item',
 675          'page-tab',
 676          '_wpnonce',
 677      );
 678  
 679      ?>
 680      <div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv">
 681          <ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs">
 682              <li <?php echo ( 'most-recent' == $current_tab ? ' class="tabs"' : '' ); ?>>
 683                  <a class="nav-tab-link" data-type="tabs-panel-posttype-<?php echo esc_attr( $post_type_name ); ?>-most-recent" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'most-recent', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent">
 684                      <?php _e( 'Most Recent' ); ?>
 685                  </a>
 686              </li>
 687              <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
 688                  <a class="nav-tab-link" data-type="<?php echo esc_attr( $post_type_name ); ?>-all" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#<?php echo $post_type_name; ?>-all">
 689                      <?php _e( 'View All' ); ?>
 690                  </a>
 691              </li>
 692              <li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>>
 693                  <a class="nav-tab-link" data-type="tabs-panel-posttype-<?php echo esc_attr( $post_type_name ); ?>-search" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-search">
 694                      <?php _e( 'Search'); ?>
 695                  </a>
 696              </li>
 697          </ul><!-- .posttype-tabs -->
 698  
 699          <div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent" class="tabs-panel <?php
 700              echo ( 'most-recent' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 701          ?>">
 702              <ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear">
 703                  <?php
 704                  $recent_args = array_merge( $args, array( 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => 15 ) );
 705                  $most_recent = $get_posts->query( $recent_args );
 706                  $args['walker'] = $walker;
 707                  echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $most_recent), 0, (object) $args );
 708                  ?>
 709              </ul>
 710          </div><!-- /.tabs-panel -->
 711  
 712          <div class="tabs-panel <?php
 713              echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 714          ?>" id="tabs-panel-posttype-<?php echo $post_type_name; ?>-search">
 715              <?php
 716              if ( isset( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
 717                  $searched = esc_attr( $_REQUEST['quick-search-posttype-' . $post_type_name] );
 718                  $search_results = get_posts( array( 's' => $searched, 'post_type' => $post_type_name, 'fields' => 'all', 'order' => 'DESC', ) );
 719              } else {
 720                  $searched = '';
 721                  $search_results = array();
 722              }
 723              ?>
 724              <p class="quick-search-wrap">
 725                  <input type="search" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-posttype-<?php echo $post_type_name; ?>" />
 726                  <span class="spinner"></span>
 727                  <?php submit_button( __( 'Search' ), 'button-small quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?>
 728              </p>
 729  
 730              <ul id="<?php echo $post_type_name; ?>-search-checklist" data-wp-lists="list:<?php echo $post_type_name?>" class="categorychecklist form-no-clear">
 731              <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
 732                  <?php
 733                  $args['walker'] = $walker;
 734                  echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args );
 735                  ?>
 736              <?php elseif ( is_wp_error( $search_results ) ) : ?>
 737                  <li><?php echo $search_results->get_error_message(); ?></li>
 738              <?php elseif ( ! empty( $searched ) ) : ?>
 739                  <li><?php _e('No results found.'); ?></li>
 740              <?php endif; ?>
 741              </ul>
 742          </div><!-- /.tabs-panel -->
 743  
 744          <div id="<?php echo $post_type_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php
 745              echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 746          ?>">
 747              <?php if ( ! empty( $page_links ) ) : ?>
 748                  <div class="add-menu-item-pagelinks">
 749                      <?php echo $page_links; ?>
 750                  </div>
 751              <?php endif; ?>
 752              <ul id="<?php echo $post_type_name; ?>checklist" data-wp-lists="list:<?php echo $post_type_name?>" class="categorychecklist form-no-clear">
 753                  <?php
 754                  $args['walker'] = $walker;
 755  
 756                  // if we're dealing with pages, let's put a checkbox for the front page at the top of the list
 757                  if ( 'page' == $post_type_name ) {
 758                      $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0;
 759                      if ( ! empty( $front_page ) ) {
 760                          $front_page_obj = get_post( $front_page );
 761                          $front_page_obj->front_or_home = true;
 762                          array_unshift( $posts, $front_page_obj );
 763                      } else {
 764                          $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1;
 765                          array_unshift( $posts, (object) array(
 766                              'front_or_home' => true,
 767                              'ID' => 0,
 768                              'object_id' => $_nav_menu_placeholder,
 769                              'post_content' => '',
 770                              'post_excerpt' => '',
 771                              'post_parent' => '',
 772                              'post_title' => _x('Home', 'nav menu home label'),
 773                              'post_type' => 'nav_menu_item',
 774                              'type' => 'custom',
 775                              'url' => home_url('/'),
 776                          ) );
 777                      }
 778                  }
 779  
 780                  $posts = apply_filters( 'nav_menu_items_'.$post_type_name, $posts, $args, $post_type );
 781                  $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
 782  
 783                  if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
 784                      $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items);
 785  
 786                  }
 787  
 788                  echo $checkbox_items;
 789                  ?>
 790              </ul>
 791              <?php if ( ! empty( $page_links ) ) : ?>
 792                  <div class="add-menu-item-pagelinks">
 793                      <?php echo $page_links; ?>
 794                  </div>
 795              <?php endif; ?>
 796          </div><!-- /.tabs-panel -->
 797  
 798          <p class="button-controls">
 799              <span class="list-controls">
 800                  <a href="<?php
 801                      echo esc_url( add_query_arg(
 802                          array(
 803                              $post_type_name . '-tab' => 'all',
 804                              'selectall' => 1,
 805                          ),
 806                          remove_query_arg( $removed_args )
 807                      ));
 808                  ?>#posttype-<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a>
 809              </span>
 810  
 811              <span class="add-to-menu">
 812                  <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-' . $post_type_name ); ?>" />
 813                  <span class="spinner"></span>
 814              </span>
 815          </p>
 816  
 817      </div><!-- /.posttypediv -->
 818      <?php
 819  }
 820  
 821  /**
 822   * Displays a metabox for a taxonomy menu item.
 823   *
 824   * @since 3.0.0
 825   *
 826   * @param string $object Not used.
 827   * @param string $taxonomy The taxonomy object.
 828   */
 829  function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) {
 830      global $nav_menu_selected_id;
 831      $taxonomy_name = $taxonomy['args']->name;
 832  
 833      // paginate browsing for large numbers of objects
 834      $per_page = 50;
 835      $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
 836      $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
 837  
 838      $args = array(
 839          'child_of' => 0,
 840          'exclude' => '',
 841          'hide_empty' => false,
 842          'hierarchical' => 1,
 843          'include' => '',
 844          'number' => $per_page,
 845          'offset' => $offset,
 846          'order' => 'ASC',
 847          'orderby' => 'name',
 848          'pad_counts' => false,
 849      );
 850  
 851      $terms = get_terms( $taxonomy_name, $args );
 852  
 853      if ( ! $terms || is_wp_error($terms) ) {
 854          echo '<p>' . __( 'No items.' ) . '</p>';
 855          return;
 856      }
 857  
 858      $num_pages = ceil( wp_count_terms( $taxonomy_name , array_merge( $args, array('number' => '', 'offset' => '') ) ) / $per_page );
 859  
 860      $page_links = paginate_links( array(
 861          'base' => add_query_arg(
 862              array(
 863                  $taxonomy_name . '-tab' => 'all',
 864                  'paged' => '%#%',
 865                  'item-type' => 'taxonomy',
 866                  'item-object' => $taxonomy_name,
 867              )
 868          ),
 869          'format' => '',
 870          'prev_text' => __('&laquo;'),
 871          'next_text' => __('&raquo;'),
 872          'total' => $num_pages,
 873          'current' => $pagenum
 874      ));
 875  
 876      $db_fields = false;
 877      if ( is_taxonomy_hierarchical( $taxonomy_name ) ) {
 878          $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' );
 879      }
 880  
 881      $walker = new Walker_Nav_Menu_Checklist( $db_fields );
 882  
 883      $current_tab = 'most-used';
 884      if ( isset( $_REQUEST[$taxonomy_name . '-tab'] ) && in_array( $_REQUEST[$taxonomy_name . '-tab'], array('all', 'most-used', 'search') ) ) {
 885          $current_tab = $_REQUEST[$taxonomy_name . '-tab'];
 886      }
 887  
 888      if ( ! empty( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) {
 889          $current_tab = 'search';
 890      }
 891  
 892      $removed_args = array(
 893          'action',
 894          'customlink-tab',
 895          'edit-menu-item',
 896          'menu-item',
 897          'page-tab',
 898          '_wpnonce',
 899      );
 900  
 901      ?>
 902      <div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv">
 903          <ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs">
 904              <li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>>
 905                  <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">
 906                      <?php _e( 'Most Used' ); ?>
 907                  </a>
 908              </li>
 909              <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
 910                  <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">
 911                      <?php _e( 'View All' ); ?>
 912                  </a>
 913              </li>
 914              <li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>>
 915                  <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; ?>">
 916                      <?php _e( 'Search' ); ?>
 917                  </a>
 918              </li>
 919          </ul><!-- .taxonomy-tabs -->
 920  
 921          <div id="tabs-panel-<?php echo $taxonomy_name; ?>-pop" class="tabs-panel <?php
 922              echo ( 'most-used' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 923          ?>">
 924              <ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
 925                  <?php
 926                  $popular_terms = get_terms( $taxonomy_name, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
 927                  $args['walker'] = $walker;
 928                  echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $popular_terms), 0, (object) $args );
 929                  ?>
 930              </ul>
 931          </div><!-- /.tabs-panel -->
 932  
 933          <div id="tabs-panel-<?php echo $taxonomy_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php
 934              echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 935          ?>">
 936              <?php if ( ! empty( $page_links ) ) : ?>
 937                  <div class="add-menu-item-pagelinks">
 938                      <?php echo $page_links; ?>
 939                  </div>
 940              <?php endif; ?>
 941              <ul id="<?php echo $taxonomy_name; ?>checklist" data-wp-lists="list:<?php echo $taxonomy_name?>" class="categorychecklist form-no-clear">
 942                  <?php
 943                  $args['walker'] = $walker;
 944                  echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $terms), 0, (object) $args );
 945                  ?>
 946              </ul>
 947              <?php if ( ! empty( $page_links ) ) : ?>
 948                  <div class="add-menu-item-pagelinks">
 949                      <?php echo $page_links; ?>
 950                  </div>
 951              <?php endif; ?>
 952          </div><!-- /.tabs-panel -->
 953  
 954          <div class="tabs-panel <?php
 955              echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
 956          ?>" id="tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>">
 957              <?php
 958              if ( isset( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) {
 959                  $searched = esc_attr( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] );
 960                  $search_results = get_terms( $taxonomy_name, array( 'name__like' => $searched, 'fields' => 'all', 'orderby' => 'count', 'order' => 'DESC', 'hierarchical' => false ) );
 961              } else {
 962                  $searched = '';
 963                  $search_results = array();
 964              }
 965              ?>
 966              <p class="quick-search-wrap">
 967                  <input type="search" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" />
 968                  <span class="spinner"></span>
 969                  <?php submit_button( __( 'Search' ), 'button-small quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?>
 970              </p>
 971  
 972              <ul id="<?php echo $taxonomy_name; ?>-search-checklist" data-wp-lists="list:<?php echo $taxonomy_name?>" class="categorychecklist form-no-clear">
 973              <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?>
 974                  <?php
 975                  $args['walker'] = $walker;
 976                  echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args );
 977                  ?>
 978              <?php elseif ( is_wp_error( $search_results ) ) : ?>
 979                  <li><?php echo $search_results->get_error_message(); ?></li>
 980              <?php elseif ( ! empty( $searched ) ) : ?>
 981                  <li><?php _e('No results found.'); ?></li>
 982              <?php endif; ?>
 983              </ul>
 984          </div><!-- /.tabs-panel -->
 985  
 986          <p class="button-controls">
 987              <span class="list-controls">
 988                  <a href="<?php
 989                      echo esc_url(add_query_arg(
 990                          array(
 991                              $taxonomy_name . '-tab' => 'all',
 992                              'selectall' => 1,
 993                          ),
 994                          remove_query_arg($removed_args)
 995                      ));
 996                  ?>#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all"><?php _e('Select All'); ?></a>
 997              </span>
 998  
 999              <span class="add-to-menu">
1000                  <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-taxonomy-menu-item" id="<?php esc_attr_e( 'submit-taxonomy-' . $taxonomy_name ); ?>" />
1001                  <span class="spinner"></span>
1002              </span>
1003          </p>
1004  
1005      </div><!-- /.taxonomydiv -->
1006      <?php
1007  }
1008  
1009  /**
1010   * Save posted nav menu item data.
1011   *
1012   * @since 3.0.0
1013   *
1014   * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item.
1015   * @param array $menu_data The unsanitized posted menu item data.
1016   * @return array The database IDs of the items saved
1017   */
1018  function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) {
1019      $menu_id = (int) $menu_id;
1020      $items_saved = array();
1021  
1022      if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) {
1023  
1024          // Loop through all the menu items' POST values
1025          foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) {
1026              if (
1027                  empty( $_item_object_data['menu-item-object-id'] ) && // checkbox is not checked
1028                  (
1029                      ! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set
1030                      in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default
1031                      ! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || // or it's not a custom menu item (but not the custom home page)
1032                      ! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists
1033                  )
1034              ) {
1035                  continue; // then this potential menu item is not getting added to this menu
1036              }
1037  
1038              // if this possible menu item doesn't actually have a menu database ID yet
1039              if (
1040                  empty( $_item_object_data['menu-item-db-id'] ) ||
1041                  ( 0 > $_possible_db_id ) ||
1042                  $_possible_db_id != $_item_object_data['menu-item-db-id']
1043              ) {
1044                  $_actual_db_id = 0;
1045              } else {
1046                  $_actual_db_id = (int) $_item_object_data['menu-item-db-id'];
1047              }
1048  
1049              $args = array(
1050                  'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ),
1051                  'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ),
1052                  'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ),
1053                  'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ),
1054                  'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ),
1055                  'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ),
1056                  'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ),
1057                  'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ),
1058                  'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ),
1059                  'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ),
1060                  'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ),
1061                  'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ),
1062                  'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ),
1063              );
1064  
1065              $items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args );
1066  
1067          }
1068      }
1069      return $items_saved;
1070  }
1071  
1072  /**
1073   * Adds custom arguments to some of the meta box object types.
1074   *
1075   * @since 3.0.0
1076   *
1077   * @access private
1078   *
1079   * @param object $object The post type or taxonomy meta-object.
1080   * @return object The post type of taxonomy object.
1081   */
1082  function _wp_nav_menu_meta_box_object( $object = null ) {
1083      if ( isset( $object->name ) ) {
1084  
1085          if ( 'page' == $object->name ) {
1086              $object->_default_query = array(
1087                  'orderby' => 'menu_order title',
1088                  'post_status' => 'publish',
1089              );
1090  
1091          // posts should show only published items
1092          } elseif ( 'post' == $object->name ) {
1093              $object->_default_query = array(
1094                  'post_status' => 'publish',
1095              );
1096  
1097          // cats should be in reverse chronological order
1098          } elseif ( 'category' == $object->name ) {
1099              $object->_default_query = array(
1100                  'orderby' => 'id',
1101                  'order' => 'DESC',
1102              );
1103  
1104          // custom post types should show only published items
1105          } else {
1106              $object->_default_query = array(
1107                  'post_status' => 'publish',
1108              );
1109          }
1110      }
1111  
1112      return $object;
1113  }
1114  
1115  /**
1116   * Returns the menu formatted to edit.
1117   *
1118   * @since 3.0.0
1119   *
1120   * @param string $menu_id The ID of the menu to format.
1121   * @return string|WP_Error $output The menu formatted to edit or error object on failure.
1122   */
1123  function wp_get_nav_menu_to_edit( $menu_id = 0 ) {
1124      $menu = wp_get_nav_menu_object( $menu_id );
1125  
1126      // If the menu exists, get its items.
1127      if ( is_nav_menu( $menu ) ) {
1128          $menu_items = wp_get_nav_menu_items( $menu->term_id, array('post_status' => 'any') );
1129          $result = '<div id="menu-instructions" class="post-body-plain';
1130          $result .= ( ! empty($menu_items) ) ? ' menu-instructions-inactive">' : '">';
1131          $result .= '<p>' . __( 'Add menu items (i.e. pages, links, categories) from the column on the left.' ) . '</p>';
1132          $result .= '</div>';
1133  
1134          if( empty($menu_items) )
1135              return $result . ' <ul class="menu" id="menu-to-edit"> </ul>';
1136  
1137          $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id );
1138  
1139          if ( class_exists( $walker_class_name ) )
1140              $walker = new $walker_class_name;
1141          else
1142              return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) );
1143  
1144          $some_pending_menu_items = $some_invalid_menu_items = false;
1145          foreach( (array) $menu_items as $menu_item ) {
1146              if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status )
1147                  $some_pending_menu_items = true;
1148              if ( ! empty( $menu_item->_invalid ) )
1149                  $some_invalid_menu_items = true;
1150          }
1151  
1152          if ( $some_pending_menu_items )
1153              $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>';
1154  
1155          if ( $some_invalid_menu_items )
1156              $result .= '<div class="error inline"><p>' . __('There are some invalid menu items. Please check or delete them.') . '</p></div>';
1157  
1158          $result .= '<ul class="menu" id="menu-to-edit"> ';
1159          $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) );
1160          $result .= ' </ul> ';
1161          return $result;
1162      } elseif ( is_wp_error( $menu ) ) {
1163          return $menu;
1164      }
1165  
1166  }
1167  
1168  /**
1169   * Returns the columns for the nav menus page.
1170   *
1171   * @since 3.0.0
1172   *
1173   * @return string|WP_Error $output The menu formatted to edit or error object on failure.
1174   */
1175  function wp_nav_menu_manage_columns() {
1176      return array(
1177          '_title' => __('Show advanced menu properties'),
1178          'cb' => '<input type="checkbox" />',
1179          'link-target' => __('Link Target'),
1180          'css-classes' => __('CSS Classes'),
1181          'xfn' => __('Link Relationship (XFN)'),
1182          'description' => __('Description'),
1183      );
1184  }
1185  
1186  /**
1187   * Deletes orphaned draft menu items
1188   *
1189   * @access private
1190   * @since 3.0.0
1191   *
1192   */
1193  function _wp_delete_orphaned_draft_menu_items() {
1194      global $wpdb;
1195      $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
1196  
1197      // delete orphaned draft menu items
1198      $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) );
1199  
1200      foreach( (array) $menu_items_to_delete as $menu_item_id )
1201          wp_delete_post( $menu_item_id, true );
1202  }
1203  add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items');
1204  
1205  /**
1206   * Saves nav menu items
1207   *
1208   * @since 3.6.0
1209   *
1210   * @uses wp_get_nav_menu_items() to retrieve the nav menu's menu items
1211   * @uses wp_defer_term_counter() to enable then disable term counting
1212   *
1213   * @param int|string $nav_menu_selected_id (id, slug, or name ) of the currently-selected menu
1214   * @param string $nav_menu_selected_title Title of the currently-selected menu
1215   * @return array $messages The menu updated message
1216   */
1217  function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_selected_title ) {
1218      $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish' ) );
1219  
1220      $menu_items = array();
1221      // Index menu items by db ID
1222      foreach ( $unsorted_menu_items as $_item )
1223          $menu_items[$_item->db_id] = $_item;
1224  
1225      $post_fields = array(
1226          'menu-item-db-id', 'menu-item-object-id', 'menu-item-object',
1227          'menu-item-parent-id', 'menu-item-position', 'menu-item-type',
1228          'menu-item-title', 'menu-item-url', 'menu-item-description',
1229          'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn'
1230      );
1231  
1232      wp_defer_term_counting( true );
1233      // Loop through all the menu items' POST variables
1234      if ( ! empty( $_POST['menu-item-db-id'] ) ) {
1235          foreach( (array) $_POST['menu-item-db-id'] as $_key => $k ) {
1236  
1237              // Menu item title can't be blank
1238              if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' == $_POST['menu-item-title'][ $_key ] )
1239                  continue;
1240  
1241              $args = array();
1242              foreach ( $post_fields as $field )
1243                  $args[$field] = isset( $_POST[$field][$_key] ) ? $_POST[$field][$_key] : '';
1244  
1245              $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args );
1246  
1247              if ( is_wp_error( $menu_item_db_id ) )
1248                  $messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>';
1249              elseif ( isset( $menu_items[$menu_item_db_id] ) )
1250                  unset( $menu_items[$menu_item_db_id] );
1251          }
1252      }
1253  
1254      // Remove menu items from the menu that weren't in $_POST
1255      if ( ! empty( $menu_items ) ) {
1256          foreach ( array_keys( $menu_items ) as $menu_item_id ) {
1257              if ( is_nav_menu_item( $menu_item_id ) ) {
1258                  wp_delete_post( $menu_item_id );
1259              }
1260          }
1261      }
1262  
1263      // Store 'auto-add' pages.
1264      $auto_add = ! empty( $_POST['auto-add-pages'] );
1265      $nav_menu_option = (array) get_option( 'nav_menu_options' );
1266      if ( ! isset( $nav_menu_option['auto_add'] ) )
1267          $nav_menu_option['auto_add'] = array();
1268      if ( $auto_add ) {
1269          if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) )
1270              $nav_menu_option['auto_add'][] = $nav_menu_selected_id;
1271      } else {
1272          if ( false !== ( $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) )
1273              unset( $nav_menu_option['auto_add'][$key] );
1274      }
1275      // Remove nonexistent/deleted menus
1276      $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) );
1277      update_option( 'nav_menu_options', $nav_menu_option );
1278  
1279      wp_defer_term_counting( false );
1280  
1281      do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
1282  
1283      $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%1$s</strong> has been updated.' ), $nav_menu_selected_title ) . '</p></div>';
1284      unset( $menu_items, $unsorted_menu_items );
1285  
1286      return $messages;
1287  }


Generated: Mon May 20 03:56:25 2013 Hosted by follow the white rabbit.