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