From 7623fc24ac33169585ffcf1f890ece21f3248d38 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 24 Feb 2010 00:37:15 +0000 Subject: [PATCH] dont show items when menu empty, See #11817 git-svn-id: https://develop.svn.wordpress.org/trunk@13354 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/custom-navigation.php | 33 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/wp-includes/custom-navigation.php b/wp-includes/custom-navigation.php index 5dbf666fe1..e989816eec 100644 --- a/wp-includes/custom-navigation.php +++ b/wp-includes/custom-navigation.php @@ -56,26 +56,27 @@ function wp_get_nav_menus() { function wp_get_nav_menu_items( $menu, $args = array() ) { $items = get_objects_in_term( (int) $menu, 'nav_menu' ); - $defaults = array( 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order' ); - $args = wp_parse_args($args, $defaults); - if ( count( $items ) > 1 ) - $args['include'] = implode( ',', $items ); - else - $args['include'] = $items[0]; + if ( ! empty( $items ) ) { + $defaults = array( 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order' ); + $args = wp_parse_args($args, $defaults); + if ( count( $items ) > 1 ) + $args['include'] = implode( ',', $items ); + else + $args['include'] = $items[0]; - $items = get_posts( $args ); + $items = get_posts( $args ); - if ( ARRAY_A == $args['output'] ) { - $output = array(); - foreach ( $items as $item ) { - $output[$item->$args['output_key']] = $item; + if ( ARRAY_A == $args['output'] ) { + $output = array(); + foreach ( $items as $item ) { + $output[$item->$args['output_key']] = $item; + } + unset($items); + ksort($output); + return $output; } - unset($items); - ksort($output); - return $output; - } else { - return $items; } + return $items; } function setup_menu_item($menu_item, $type = 'item', $position = 0) {