Ticket #13822: 13822.2.diff
File 13822.2.diff, 3.8 KB (added by , 15 years ago) |
---|
-
wp-includes/nav-menu-template.php
151 151 if ( ! $menu && !$args->theme_location ) { 152 152 $menus = wp_get_nav_menus(); 153 153 foreach ( $menus as $menu_maybe ) { 154 if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id ) ) {154 if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id, array( 'public' => true ) ) ) { 155 155 $menu = $menu_maybe; 156 156 break; 157 157 } … … 160 160 161 161 // If the menu exists, get its items. 162 162 if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ) 163 $menu_items = wp_get_nav_menu_items( $menu->term_id );163 $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'public' => true ) ); 164 164 165 165 // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists 166 166 if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) -
wp-includes/nav-menu.php
454 454 455 455 $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 456 456 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, 457 'update_post_term_cache' => false );457 'update_post_term_cache' => false, 'public' => false ); 458 458 $args = wp_parse_args( $args, $defaults ); 459 $public_consumption = $args['public']; 460 unset( $args['public'] ); 459 461 if ( count( $items ) > 1 ) 460 462 $args['include'] = implode( ',', $items ); 461 463 else … … 497 499 unset($terms); 498 500 } 499 501 500 $items = array_map( 'wp_setup_nav_menu_item', $items ); 502 if ( $public_consumption ) 503 $items = array_filter( array_map( 'wp_setup_nav_menu_item_published', $items ) ); 504 else 505 $items = array_map( 'wp_setup_nav_menu_item', $items ); 501 506 502 507 if ( ARRAY_A == $args['output'] ) { 503 508 $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; … … 512 517 } 513 518 514 519 /** 520 * Callback that wraps wp_setup_nav_menu_item() to ensure only published posts are shown publicly. 521 * 522 * @uses wp_setup_nav_menu_item() 523 * @since 3.0.0 524 */ 525 function wp_setup_nav_menu_item_published( $menu_item ) { 526 return wp_setup_nav_menu_item( $menu_item, array( 'post_object_status' => 'publish' ) ); 527 } 528 529 /** 515 530 * Decorates a menu item object with the shared navigation menu item properties. 516 531 * 517 532 * Properties: … … 533 548 * @since 3.0.0 534 549 * 535 550 * @param object $menu_item The menu item to modify. 551 * @param array $args 536 552 * @return object $menu_item The menu item with standard menu item properties. 537 553 */ 538 function wp_setup_nav_menu_item( $menu_item ) { 554 function wp_setup_nav_menu_item( $menu_item, $args ) { 555 $defaults = array( 'post_object_status' => 'any' ); 556 $args = wp_parse_args( $args, $defaults ); 557 539 558 if ( isset( $menu_item->post_type ) ) { 540 559 if ( 'nav_menu_item' == $menu_item->post_type ) { 541 560 $menu_item->db_id = (int) $menu_item->ID; … … 545 564 $menu_item->type = empty( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type; 546 565 547 566 if ( 'post_type' == $menu_item->type ) { 567 $original_object = get_post( $menu_item->object_id ); 568 if ( 'publish' == $args['post_object_status'] && $original_object->post_status != 'publish' ) 569 return null; 570 548 571 $object = get_post_type_object( $menu_item->object ); 549 572 $menu_item->type_label = $object->labels->singular_name; 550 573 $menu_item->url = get_permalink( $menu_item->object_id ); 551 574 552 $original_object = get_post( $menu_item->object_id );553 575 $original_title = $original_object->post_title; 554 576 $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; 555 577