17 * |
17 * |
18 * @param string $output Passed by reference. |
18 * @param string $output Passed by reference. |
19 * @param int $depth Depth of menu item. Used for padding. |
19 * @param int $depth Depth of menu item. Used for padding. |
20 * @param array $args Not used. |
20 * @param array $args Not used. |
21 */ |
21 */ |
22 function start_lvl( &$output, $depth = 0, $args = array() ) {} |
22 public function start_lvl( &$output, $depth = 0, $args = array() ) {} |
23 |
23 |
24 /** |
24 /** |
25 * Ends the list of after the elements are added. |
25 * Ends the list of after the elements are added. |
26 * |
26 * |
27 * @see Walker_Nav_Menu::end_lvl() |
27 * @see Walker_Nav_Menu::end_lvl() |
30 * |
30 * |
31 * @param string $output Passed by reference. |
31 * @param string $output Passed by reference. |
32 * @param int $depth Depth of menu item. Used for padding. |
32 * @param int $depth Depth of menu item. Used for padding. |
33 * @param array $args Not used. |
33 * @param array $args Not used. |
34 */ |
34 */ |
35 function end_lvl( &$output, $depth = 0, $args = array() ) {} |
35 public function end_lvl( &$output, $depth = 0, $args = array() ) {} |
36 |
36 |
37 /** |
37 /** |
38 * Start the element output. |
38 * Start the element output. |
39 * |
39 * |
40 * @see Walker_Nav_Menu::start_el() |
40 * @see Walker_Nav_Menu::start_el() |
44 * @param object $item Menu item data object. |
44 * @param object $item Menu item data object. |
45 * @param int $depth Depth of menu item. Used for padding. |
45 * @param int $depth Depth of menu item. Used for padding. |
46 * @param array $args Not used. |
46 * @param array $args Not used. |
47 * @param int $id Not used. |
47 * @param int $id Not used. |
48 */ |
48 */ |
49 function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
49 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
50 global $_wp_nav_menu_max_depth; |
50 global $_wp_nav_menu_max_depth; |
51 $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; |
51 $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; |
52 |
52 |
53 ob_start(); |
53 ob_start(); |
54 $item_id = esc_attr( $item->ID ); |
54 $item_id = esc_attr( $item->ID ); |
184 </p> |
184 </p> |
185 |
185 |
186 <p class="field-move hide-if-no-js description description-wide"> |
186 <p class="field-move hide-if-no-js description description-wide"> |
187 <label> |
187 <label> |
188 <span><?php _e( 'Move' ); ?></span> |
188 <span><?php _e( 'Move' ); ?></span> |
189 <a href="#" class="menus-move-up"><?php _e( 'Up one' ); ?></a> |
189 <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></a> |
190 <a href="#" class="menus-move-down"><?php _e( 'Down one' ); ?></a> |
190 <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></a> |
191 <a href="#" class="menus-move-left"></a> |
191 <a href="#" class="menus-move menus-move-left" data-dir="left"></a> |
192 <a href="#" class="menus-move-right"></a> |
192 <a href="#" class="menus-move menus-move-right" data-dir="right"></a> |
193 <a href="#" class="menus-move-top"><?php _e( 'To the top' ); ?></a> |
193 <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></a> |
194 </label> |
194 </label> |
195 </p> |
195 </p> |
196 |
196 |
197 <div class="menu-item-actions description-wide submitbox"> |
197 <div class="menu-item-actions description-wide submitbox"> |
198 <?php if( 'custom' != $item->type && $original_title !== false ) : ?> |
198 <?php if( 'custom' != $item->type && $original_title !== false ) : ?> |
229 } // Walker_Nav_Menu_Edit |
229 } // Walker_Nav_Menu_Edit |
230 |
230 |
231 /** |
231 /** |
232 * Create HTML list of nav menu input items. |
232 * Create HTML list of nav menu input items. |
233 * |
233 * |
234 * @package WordPress |
|
235 * @since 3.0.0 |
234 * @since 3.0.0 |
236 * @uses Walker_Nav_Menu |
235 * @uses Walker_Nav_Menu |
237 */ |
236 */ |
238 class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { |
237 class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { |
239 function __construct( $fields = false ) { |
238 public function __construct( $fields = false ) { |
240 if ( $fields ) { |
239 if ( $fields ) { |
241 $this->db_fields = $fields; |
240 $this->db_fields = $fields; |
242 } |
241 } |
243 } |
242 } |
244 |
243 |
251 * |
250 * |
252 * @param string $output Passed by reference. Used to append additional content. |
251 * @param string $output Passed by reference. Used to append additional content. |
253 * @param int $depth Depth of page. Used for padding. |
252 * @param int $depth Depth of page. Used for padding. |
254 * @param array $args Not used. |
253 * @param array $args Not used. |
255 */ |
254 */ |
256 function start_lvl( &$output, $depth = 0, $args = array() ) { |
255 public function start_lvl( &$output, $depth = 0, $args = array() ) { |
257 $indent = str_repeat( "\t", $depth ); |
256 $indent = str_repeat( "\t", $depth ); |
258 $output .= "\n$indent<ul class='children'>\n"; |
257 $output .= "\n$indent<ul class='children'>\n"; |
259 } |
258 } |
260 |
259 |
261 /** |
260 /** |
267 * |
266 * |
268 * @param string $output Passed by reference. Used to append additional content. |
267 * @param string $output Passed by reference. Used to append additional content. |
269 * @param int $depth Depth of page. Used for padding. |
268 * @param int $depth Depth of page. Used for padding. |
270 * @param array $args Not used. |
269 * @param array $args Not used. |
271 */ |
270 */ |
272 function end_lvl( &$output, $depth = 0, $args = array() ) { |
271 public function end_lvl( &$output, $depth = 0, $args = array() ) { |
273 $indent = str_repeat( "\t", $depth ); |
272 $indent = str_repeat( "\t", $depth ); |
274 $output .= "\n$indent</ul>"; |
273 $output .= "\n$indent</ul>"; |
275 } |
274 } |
276 |
275 |
277 /** |
276 /** |
285 * @param object $item Menu item data object. |
284 * @param object $item Menu item data object. |
286 * @param int $depth Depth of menu item. Used for padding. |
285 * @param int $depth Depth of menu item. Used for padding. |
287 * @param array $args Not used. |
286 * @param array $args Not used. |
288 * @param int $id Not used. |
287 * @param int $id Not used. |
289 */ |
288 */ |
290 function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
289 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
291 global $_nav_menu_placeholder; |
290 global $_nav_menu_placeholder; |
292 |
291 |
293 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; |
292 $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; |
294 $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder; |
293 $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder; |
295 $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0; |
294 $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0; |
355 if ( isset( $request['ID'] ) ) { |
354 if ( isset( $request['ID'] ) ) { |
356 $object_id = (int) $request['ID']; |
355 $object_id = (int) $request['ID']; |
357 if ( 'markup' == $response_format ) { |
356 if ( 'markup' == $response_format ) { |
358 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); |
357 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); |
359 } elseif ( 'json' == $response_format ) { |
358 } elseif ( 'json' == $response_format ) { |
360 $post_obj = get_post( $object_id ); |
359 echo wp_json_encode( |
361 echo json_encode( |
|
362 array( |
360 array( |
363 'ID' => $object_id, |
361 'ID' => $object_id, |
364 'post_title' => get_the_title( $object_id ), |
362 'post_title' => get_the_title( $object_id ), |
365 'post_type' => get_post_type( $object_id ), |
363 'post_type' => get_post_type( $object_id ), |
366 ) |
364 ) |
373 $object_id = (int) $request['ID']; |
371 $object_id = (int) $request['ID']; |
374 if ( 'markup' == $response_format ) { |
372 if ( 'markup' == $response_format ) { |
375 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); |
373 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); |
376 } elseif ( 'json' == $response_format ) { |
374 } elseif ( 'json' == $response_format ) { |
377 $post_obj = get_term( $object_id, $object_type ); |
375 $post_obj = get_term( $object_id, $object_type ); |
378 echo json_encode( |
376 echo wp_json_encode( |
379 array( |
377 array( |
380 'ID' => $object_id, |
378 'ID' => $object_id, |
381 'post_title' => $post_obj->name, |
379 'post_title' => $post_obj->name, |
382 'post_type' => $object_type, |
380 'post_type' => $object_type, |
383 ) |
381 ) |
401 the_post(); |
399 the_post(); |
402 if ( 'markup' == $response_format ) { |
400 if ( 'markup' == $response_format ) { |
403 $var_by_ref = get_the_ID(); |
401 $var_by_ref = get_the_ID(); |
404 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args ); |
402 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args ); |
405 } elseif ( 'json' == $response_format ) { |
403 } elseif ( 'json' == $response_format ) { |
406 echo json_encode( |
404 echo wp_json_encode( |
407 array( |
405 array( |
408 'ID' => get_the_ID(), |
406 'ID' => get_the_ID(), |
409 'post_title' => get_the_title(), |
407 'post_title' => get_the_title(), |
410 'post_type' => get_post_type(), |
408 'post_type' => get_post_type(), |
411 ) |
409 ) |
422 return; |
420 return; |
423 foreach( (array) $terms as $term ) { |
421 foreach( (array) $terms as $term ) { |
424 if ( 'markup' == $response_format ) { |
422 if ( 'markup' == $response_format ) { |
425 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args ); |
423 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args ); |
426 } elseif ( 'json' == $response_format ) { |
424 } elseif ( 'json' == $response_format ) { |
427 echo json_encode( |
425 echo wp_json_encode( |
428 array( |
426 array( |
429 'ID' => $term->term_id, |
427 'ID' => $term->term_id, |
430 'post_title' => $term->name, |
428 'post_title' => $term->name, |
431 'post_type' => $matches[2], |
429 'post_type' => $matches[2], |
432 ) |
430 ) |
444 * @since 3.0.0 |
442 * @since 3.0.0 |
445 **/ |
443 **/ |
446 function wp_nav_menu_setup() { |
444 function wp_nav_menu_setup() { |
447 // Register meta boxes |
445 // Register meta boxes |
448 wp_nav_menu_post_type_meta_boxes(); |
446 wp_nav_menu_post_type_meta_boxes(); |
449 add_meta_box( 'add-custom-links', __( 'Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); |
447 add_meta_box( 'add-custom-links', __( 'Custom Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); |
450 wp_nav_menu_taxonomy_meta_boxes(); |
448 wp_nav_menu_taxonomy_meta_boxes(); |
451 |
449 |
452 // Register advanced menu items (columns) |
450 // Register advanced menu items (columns) |
453 add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' ); |
451 add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' ); |
454 |
452 |
501 |
499 |
502 if ( ! $post_types ) |
500 if ( ! $post_types ) |
503 return; |
501 return; |
504 |
502 |
505 foreach ( $post_types as $post_type ) { |
503 foreach ( $post_types as $post_type ) { |
|
504 /** |
|
505 * Filter whether a menu items meta box will be added for the current |
|
506 * object type. |
|
507 * |
|
508 * If a falsey value is returned instead of an object, the menu items |
|
509 * meta box for the current meta box object will not be added. |
|
510 * |
|
511 * @since 3.0.0 |
|
512 * |
|
513 * @param object $meta_box_object The current object to add a menu items |
|
514 * meta box for. |
|
515 */ |
506 $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type ); |
516 $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type ); |
507 if ( $post_type ) { |
517 if ( $post_type ) { |
508 $id = $post_type->name; |
518 $id = $post_type->name; |
509 // give pages a higher priority |
519 // Give pages a higher priority. |
510 $priority = ( 'page' == $post_type->name ? 'core' : 'default' ); |
520 $priority = ( 'page' == $post_type->name ? 'core' : 'default' ); |
511 add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type ); |
521 add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type ); |
512 } |
522 } |
513 } |
523 } |
514 } |
524 } |
523 |
533 |
524 if ( !$taxonomies ) |
534 if ( !$taxonomies ) |
525 return; |
535 return; |
526 |
536 |
527 foreach ( $taxonomies as $tax ) { |
537 foreach ( $taxonomies as $tax ) { |
|
538 /** This filter is documented in wp-admin/includes/nav-menu.php */ |
528 $tax = apply_filters( 'nav_menu_meta_box_object', $tax ); |
539 $tax = apply_filters( 'nav_menu_meta_box_object', $tax ); |
529 if ( $tax ) { |
540 if ( $tax ) { |
530 $id = $tax->name; |
541 $id = $tax->name; |
531 add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax ); |
542 add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax ); |
532 } |
543 } |
537 * Check whether to disable the Menu Locations meta box submit button |
548 * Check whether to disable the Menu Locations meta box submit button |
538 * |
549 * |
539 * @since 3.6.0 |
550 * @since 3.6.0 |
540 * |
551 * |
541 * @uses global $one_theme_location_no_menus to determine if no menus exist |
552 * @uses global $one_theme_location_no_menus to determine if no menus exist |
542 * @uses disabled() to output the disabled attribute in $other_attributes param in submit_button() |
|
543 * |
553 * |
544 * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu |
554 * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu |
545 * @return string Disabled attribute if at least one menu exists, false if not |
555 * @return string Disabled attribute if at least one menu exists, false if not |
546 */ |
556 */ |
547 function wp_nav_menu_disabled_check( $nav_menu_selected_id ) { |
557 function wp_nav_menu_disabled_check( $nav_menu_selected_id ) { |
602 function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) { |
612 function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) { |
603 global $_nav_menu_placeholder, $nav_menu_selected_id; |
613 global $_nav_menu_placeholder, $nav_menu_selected_id; |
604 |
614 |
605 $post_type_name = $post_type['args']->name; |
615 $post_type_name = $post_type['args']->name; |
606 |
616 |
607 // paginate browsing for large numbers of post objects |
617 // Paginate browsing for large numbers of post objects. |
608 $per_page = 50; |
618 $per_page = 50; |
609 $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
619 $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
610 $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
620 $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
611 |
621 |
612 $args = array( |
622 $args = array( |
628 $posts = $get_posts->query( $args ); |
638 $posts = $get_posts->query( $args ); |
629 if ( ! $get_posts->post_count ) { |
639 if ( ! $get_posts->post_count ) { |
630 echo '<p>' . __( 'No items.' ) . '</p>'; |
640 echo '<p>' . __( 'No items.' ) . '</p>'; |
631 return; |
641 return; |
632 } |
642 } |
633 |
|
634 $post_type_object = get_post_type_object($post_type_name); |
|
635 |
643 |
636 $num_pages = $get_posts->max_num_pages; |
644 $num_pages = $get_posts->max_num_pages; |
637 |
645 |
638 $page_links = paginate_links( array( |
646 $page_links = paginate_links( array( |
639 'base' => add_query_arg( |
647 'base' => add_query_arg( |
648 'prev_text' => __('«'), |
656 'prev_text' => __('«'), |
649 'next_text' => __('»'), |
657 'next_text' => __('»'), |
650 'total' => $num_pages, |
658 'total' => $num_pages, |
651 'current' => $pagenum |
659 'current' => $pagenum |
652 )); |
660 )); |
653 |
|
654 if ( !$posts ) |
|
655 $error = '<li id="error">'. $post_type['args']->labels->not_found .'</li>'; |
|
656 |
661 |
657 $db_fields = false; |
662 $db_fields = false; |
658 if ( is_post_type_hierarchical( $post_type_name ) ) { |
663 if ( is_post_type_hierarchical( $post_type_name ) ) { |
659 $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' ); |
664 $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' ); |
660 } |
665 } |
754 <?php endif; ?> |
759 <?php endif; ?> |
755 <ul id="<?php echo $post_type_name; ?>checklist" data-wp-lists="list:<?php echo $post_type_name?>" class="categorychecklist form-no-clear"> |
760 <ul id="<?php echo $post_type_name; ?>checklist" data-wp-lists="list:<?php echo $post_type_name?>" class="categorychecklist form-no-clear"> |
756 <?php |
761 <?php |
757 $args['walker'] = $walker; |
762 $args['walker'] = $walker; |
758 |
763 |
759 // if we're dealing with pages, let's put a checkbox for the front page at the top of the list |
764 /* |
|
765 * If we're dealing with pages, let's put a checkbox for the front |
|
766 * page at the top of the list. |
|
767 */ |
760 if ( 'page' == $post_type_name ) { |
768 if ( 'page' == $post_type_name ) { |
761 $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0; |
769 $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0; |
762 if ( ! empty( $front_page ) ) { |
770 if ( ! empty( $front_page ) ) { |
763 $front_page_obj = get_post( $front_page ); |
771 $front_page_obj = get_post( $front_page ); |
764 $front_page_obj->front_or_home = true; |
772 $front_page_obj->front_or_home = true; |
778 'url' => home_url('/'), |
786 'url' => home_url('/'), |
779 ) ); |
787 ) ); |
780 } |
788 } |
781 } |
789 } |
782 |
790 |
783 $posts = apply_filters( 'nav_menu_items_'.$post_type_name, $posts, $args, $post_type ); |
791 /** |
|
792 * Filter the posts displayed in the 'View All' tab of the current |
|
793 * post type's menu items meta box. |
|
794 * |
|
795 * The dynamic portion of the hook name, `$post_type_name`, refers |
|
796 * to the slug of the current post type. |
|
797 * |
|
798 * @since 3.2.0 |
|
799 * |
|
800 * @see WP_Query::query() |
|
801 * |
|
802 * @param array $posts The posts for the current post type. |
|
803 * @param array $args An array of WP_Query arguments. |
|
804 * @param object $post_type The current post type object for this menu item meta box. |
|
805 */ |
|
806 $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type ); |
784 $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args ); |
807 $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args ); |
785 |
808 |
786 if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) { |
809 if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) { |
787 $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items); |
810 $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items); |
788 |
811 |
810 )); |
833 )); |
811 ?>#posttype-<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a> |
834 ?>#posttype-<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a> |
812 </span> |
835 </span> |
813 |
836 |
814 <span class="add-to-menu"> |
837 <span class="add-to-menu"> |
815 <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-' . $post_type_name ); ?>" /> |
838 <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 ); ?>" /> |
816 <span class="spinner"></span> |
839 <span class="spinner"></span> |
817 </span> |
840 </span> |
818 </p> |
841 </p> |
819 |
842 |
820 </div><!-- /.posttypediv --> |
843 </div><!-- /.posttypediv --> |
831 */ |
854 */ |
832 function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) { |
855 function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) { |
833 global $nav_menu_selected_id; |
856 global $nav_menu_selected_id; |
834 $taxonomy_name = $taxonomy['args']->name; |
857 $taxonomy_name = $taxonomy['args']->name; |
835 |
858 |
836 // paginate browsing for large numbers of objects |
859 // Paginate browsing for large numbers of objects. |
837 $per_page = 50; |
860 $per_page = 50; |
838 $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
861 $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
839 $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
862 $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
840 |
863 |
841 $args = array( |
864 $args = array( |
998 )); |
1021 )); |
999 ?>#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all"><?php _e('Select All'); ?></a> |
1022 ?>#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all"><?php _e('Select All'); ?></a> |
1000 </span> |
1023 </span> |
1001 |
1024 |
1002 <span class="add-to-menu"> |
1025 <span class="add-to-menu"> |
1003 <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-taxonomy-menu-item" id="<?php esc_attr_e( 'submit-taxonomy-' . $taxonomy_name ); ?>" /> |
1026 <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 ); ?>" /> |
1004 <span class="spinner"></span> |
1027 <span class="spinner"></span> |
1005 </span> |
1028 </span> |
1006 </p> |
1029 </p> |
1007 |
1030 |
1008 </div><!-- /.taxonomydiv --> |
1031 </div><!-- /.taxonomydiv --> |
1022 $menu_id = (int) $menu_id; |
1045 $menu_id = (int) $menu_id; |
1023 $items_saved = array(); |
1046 $items_saved = array(); |
1024 |
1047 |
1025 if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) { |
1048 if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) { |
1026 |
1049 |
1027 // Loop through all the menu items' POST values |
1050 // Loop through all the menu items' POST values. |
1028 foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) { |
1051 foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) { |
1029 if ( |
1052 if ( |
1030 empty( $_item_object_data['menu-item-object-id'] ) && // checkbox is not checked |
1053 // Checkbox is not checked. |
|
1054 empty( $_item_object_data['menu-item-object-id'] ) && |
1031 ( |
1055 ( |
1032 ! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set |
1056 // And item type either isn't set. |
1033 in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default |
1057 ! isset( $_item_object_data['menu-item-type'] ) || |
|
1058 // Or URL is the default. |
|
1059 in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || |
1034 ! ( '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) |
1060 ! ( '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) |
1035 ! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists |
1061 // Or it *is* a custom menu item that already exists. |
|
1062 ! empty( $_item_object_data['menu-item-db-id'] ) |
1036 ) |
1063 ) |
1037 ) { |
1064 ) { |
1038 continue; // then this potential menu item is not getting added to this menu |
1065 // Then this potential menu item is not getting added to this menu. |
|
1066 continue; |
1039 } |
1067 } |
1040 |
1068 |
1041 // if this possible menu item doesn't actually have a menu database ID yet |
1069 // If this possible menu item doesn't actually have a menu database ID yet. |
1042 if ( |
1070 if ( |
1043 empty( $_item_object_data['menu-item-db-id'] ) || |
1071 empty( $_item_object_data['menu-item-db-id'] ) || |
1044 ( 0 > $_possible_db_id ) || |
1072 ( 0 > $_possible_db_id ) || |
1045 $_possible_db_id != $_item_object_data['menu-item-db-id'] |
1073 $_possible_db_id != $_item_object_data['menu-item-db-id'] |
1046 ) { |
1074 ) { |
1089 $object->_default_query = array( |
1117 $object->_default_query = array( |
1090 'orderby' => 'menu_order title', |
1118 'orderby' => 'menu_order title', |
1091 'post_status' => 'publish', |
1119 'post_status' => 'publish', |
1092 ); |
1120 ); |
1093 |
1121 |
1094 // posts should show only published items |
1122 // Posts should show only published items. |
1095 } elseif ( 'post' == $object->name ) { |
1123 } elseif ( 'post' == $object->name ) { |
1096 $object->_default_query = array( |
1124 $object->_default_query = array( |
1097 'post_status' => 'publish', |
1125 'post_status' => 'publish', |
1098 ); |
1126 ); |
1099 |
1127 |
1100 // cats should be in reverse chronological order |
1128 // Categories should be in reverse chronological order. |
1101 } elseif ( 'category' == $object->name ) { |
1129 } elseif ( 'category' == $object->name ) { |
1102 $object->_default_query = array( |
1130 $object->_default_query = array( |
1103 'orderby' => 'id', |
1131 'orderby' => 'id', |
1104 'order' => 'DESC', |
1132 'order' => 'DESC', |
1105 ); |
1133 ); |
1106 |
1134 |
1107 // custom post types should show only published items |
1135 // Custom post types should show only published items. |
1108 } else { |
1136 } else { |
1109 $object->_default_query = array( |
1137 $object->_default_query = array( |
1110 'post_status' => 'publish', |
1138 'post_status' => 'publish', |
1111 ); |
1139 ); |
1112 } |
1140 } |
1118 /** |
1146 /** |
1119 * Returns the menu formatted to edit. |
1147 * Returns the menu formatted to edit. |
1120 * |
1148 * |
1121 * @since 3.0.0 |
1149 * @since 3.0.0 |
1122 * |
1150 * |
1123 * @param string $menu_id The ID of the menu to format. |
1151 * @param int $menu_id Optional. The ID of the menu to format. Default 0. |
1124 * @return string|WP_Error $output The menu formatted to edit or error object on failure. |
1152 * @return string|WP_Error $output The menu formatted to edit or error object on failure. |
1125 */ |
1153 */ |
1126 function wp_get_nav_menu_to_edit( $menu_id = 0 ) { |
1154 function wp_get_nav_menu_to_edit( $menu_id = 0 ) { |
1127 $menu = wp_get_nav_menu_object( $menu_id ); |
1155 $menu = wp_get_nav_menu_object( $menu_id ); |
1128 |
1156 |
1135 $result .= '</div>'; |
1163 $result .= '</div>'; |
1136 |
1164 |
1137 if( empty($menu_items) ) |
1165 if( empty($menu_items) ) |
1138 return $result . ' <ul class="menu" id="menu-to-edit"> </ul>'; |
1166 return $result . ' <ul class="menu" id="menu-to-edit"> </ul>'; |
1139 |
1167 |
|
1168 /** |
|
1169 * Filter the Walker class used when adding nav menu items. |
|
1170 * |
|
1171 * @since 3.0.0 |
|
1172 * |
|
1173 * @param string $class The walker class to use. Default 'Walker_Nav_Menu_Edit'. |
|
1174 * @param int $menu_id ID of the menu being rendered. |
|
1175 */ |
1140 $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id ); |
1176 $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id ); |
1141 |
1177 |
1142 if ( class_exists( $walker_class_name ) ) |
1178 if ( class_exists( $walker_class_name ) ) |
1143 $walker = new $walker_class_name; |
1179 $walker = new $walker_class_name; |
1144 else |
1180 else |
1195 */ |
1231 */ |
1196 function _wp_delete_orphaned_draft_menu_items() { |
1232 function _wp_delete_orphaned_draft_menu_items() { |
1197 global $wpdb; |
1233 global $wpdb; |
1198 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
1234 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
1199 |
1235 |
1200 // delete orphaned draft menu items |
1236 // Delete orphaned draft menu items. |
1201 $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 ) ); |
1237 $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 ) ); |
1202 |
1238 |
1203 foreach( (array) $menu_items_to_delete as $menu_item_id ) |
1239 foreach( (array) $menu_items_to_delete as $menu_item_id ) |
1204 wp_delete_post( $menu_item_id, true ); |
1240 wp_delete_post( $menu_item_id, true ); |
1205 } |
1241 } |
1207 |
1243 |
1208 /** |
1244 /** |
1209 * Saves nav menu items |
1245 * Saves nav menu items |
1210 * |
1246 * |
1211 * @since 3.6.0 |
1247 * @since 3.6.0 |
1212 * |
|
1213 * @uses wp_get_nav_menu_items() to retrieve the nav menu's menu items |
|
1214 * @uses wp_defer_term_counter() to enable then disable term counting |
|
1215 * |
1248 * |
1216 * @param int|string $nav_menu_selected_id (id, slug, or name ) of the currently-selected menu |
1249 * @param int|string $nav_menu_selected_id (id, slug, or name ) of the currently-selected menu |
1217 * @param string $nav_menu_selected_title Title of the currently-selected menu |
1250 * @param string $nav_menu_selected_title Title of the currently-selected menu |
1218 * @return array $messages The menu updated message |
1251 * @return array $messages The menu updated message |
1219 */ |
1252 */ |
1220 function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_selected_title ) { |
1253 function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_selected_title ) { |
1221 $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' ) ); |
1254 $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' ) ); |
1222 |
1255 $messages = array(); |
1223 $menu_items = array(); |
1256 $menu_items = array(); |
1224 // Index menu items by db ID |
1257 // Index menu items by db ID |
1225 foreach ( $unsorted_menu_items as $_item ) |
1258 foreach ( $unsorted_menu_items as $_item ) |
1226 $menu_items[$_item->db_id] = $_item; |
1259 $menu_items[$_item->db_id] = $_item; |
1227 |
1260 |
1279 $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) ); |
1312 $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) ); |
1280 update_option( 'nav_menu_options', $nav_menu_option ); |
1313 update_option( 'nav_menu_options', $nav_menu_option ); |
1281 |
1314 |
1282 wp_defer_term_counting( false ); |
1315 wp_defer_term_counting( false ); |
1283 |
1316 |
|
1317 /** This action is documented in wp-includes/nav-menu.php */ |
1284 do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); |
1318 do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); |
1285 |
1319 |
1286 $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%1$s</strong> has been updated.' ), $nav_menu_selected_title ) . '</p></div>'; |
1320 $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( __( '<strong>%1$s</strong> has been updated.' ), $nav_menu_selected_title ) . '</p></div>'; |
1287 unset( $menu_items, $unsorted_menu_items ); |
1321 unset( $menu_items, $unsorted_menu_items ); |
1288 |
1322 |
1289 return $messages; |
1323 return $messages; |
1290 } |
1324 } |