Fix notice for when no menus are located. see #11817

git-svn-id: http://svn.automattic.com/wordpress/trunk@13743 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-03-17 21:34:24 +00:00
parent cea2e6eaa3
commit 65423c7d16
1 changed files with 26 additions and 26 deletions

View File

@ -45,13 +45,13 @@ function wp_nav_menu( $args = array() ) {
}
}
if ( !is_wp_error($menu) && $menu)
if ( $menu && ! is_wp_error( $menu ) )
$args->menu = $menu->term_id;
$nav_menu = '';
if ( 'div' == $args->container ) {
$class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : '';
if ( is_nav_menu($menu) ) {
$nav_menu .= '<div id="menu-' . $menu->slug . '"'. $class .'>';
} else {
@ -63,7 +63,7 @@ function wp_nav_menu( $args = array() ) {
if ( 'div' == $args->container )
$nav_menu .= '</div>';
$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );
if ( $args->echo )
@ -85,25 +85,25 @@ function wp_nav_menu( $args = array() ) {
function wp_get_nav_menu( $args = array() ) {
$defaults = array( 'menu' => '', 'menu_class' => 'menu', 'context' => 'frontend',
'fallback_cb' => '', 'before_link' => '', 'after_link' => '', 'before_title' => '', 'after_title' => '', );
$args = wp_parse_args( $args, $defaults );
$args = apply_filters( 'wp_get_nav_menu_args', $args );
$args = (object) $args;
// Variable setup
$nav_menu = '';
$items = '';
$current_parent = 0;
$parent_stack = array();
$parent_menu_order = array();
// Get the menu object
$menu = wp_get_nav_menu_object( $args->menu );
// If the menu exists, get it's items.
if ( $menu && !is_wp_error($menu) )
$menu_items = wp_get_nav_menu_items( $menu->term_id, 'backend' );
// If no menu was found or if the menu has no items, call the fallback_cb
if ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) ) ) {
if ( function_exists($args->fallback_cb) ) {
@ -111,7 +111,7 @@ function wp_get_nav_menu( $args = array() ) {
return call_user_func( $args->fallback_cb, $_args );
}
}
foreach ( $menu_items as $key => $menu_item ) {
// Set up the $menu_item variables
$menu_item = wp_setup_nav_menu_item( $menu_item, 'frontend' );
@ -119,10 +119,10 @@ function wp_get_nav_menu( $args = array() ) {
$type = $menu_item->append;
$maybe_value = 'frontend' == $args->context ? '' : ' value="'. $menu_item->ID .'"';
$classes = 'frontend' == $args->context ? ' class="menu-item-type-'. $type . $menu_item->li_class .'"' : '';
$items .= '<li id="menu-item-'. $menu_item->ID .'"'. $maybe_value . $classes .'>';
$items .= wp_get_nav_menu_item( $menu_item, $args->context, $args );
// Indent children
$last_item = ( count( $menu_items ) == $menu_item->menu_order );
if ( $last_item || $current_parent != $menu_items[$key + 1]->post_parent ) {
@ -141,11 +141,11 @@ function wp_get_nav_menu( $args = array() ) {
$items .= '</li>';
}
}
// CSS class
$ul_class = $args->menu_class ? ' class="'. $args->menu_class .'"' : '';
$nav_menu .= '<ul'. $ul_class .'>';
// Allow plugins to hook into the menu to add their own <li>'s
if ( 'frontend' == $args->context ) {
$items = apply_filters( 'wp_nav_menu_items', $items, $args );
@ -154,9 +154,9 @@ function wp_get_nav_menu( $args = array() ) {
} else {
$nav_menu .= $items;
}
$nav_menu .= '</ul>';
return apply_filters( 'wp_get_nav_menu', $nav_menu );
}
@ -179,15 +179,15 @@ function wp_get_nav_menu_item( $menu_item, $context = 'frontend', $args = array(
$attributes .= ( isset($menu_item->classes) && '' != $menu_item->classes ) ? ' class="'. esc_attr($menu_item->classes) .'"' : '';
$attributes .= ( isset($menu_item->xfn) && '' != $menu_item->xfn ) ? ' rel="'. esc_attr($menu_item->xfn) .'"' : '';
$attributes .= ( isset($menu_item->url) && '' != $menu_item->url ) ? ' href="'. esc_attr($menu_item->url) .'"' : '';
$output .= esc_html( $args->before_link );
$output .= '<a'. $attributes .'>';
$output .= esc_html( $args->before_title . $menu_item->title . $args->after_title );
$output .= '</a>';
$output .= esc_html( $args->after_link );
break;
case 'backend':
$output .= '<dl><dt>';
$output .= '<span class="item-title">'. esc_html($menu_item->title) .'</span>';
@ -204,13 +204,13 @@ function wp_get_nav_menu_item( $menu_item, $context = 'frontend', $args = array(
$label = $menu_item->append;
}
$output .= '<span class="item-type">'. esc_html($label) .'</span>';
// Actions
$output .= '<a class="item-edit thickbox" id="edit'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" title="'. __('Edit Menu Item') .'" href="#TB_inline?height=540&width=300&inlineId=menu-item-settings">'. __('Edit') .'</a> | ';
$output .= '<a class="item-delete" id="delete'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'">'. __('Delete') .'</a>';
$output .= '</dt></dl>';
// Menu Item Settings
$output .= '<input type="hidden" name="menu-item-db-id[]" id="menu-item-db-id'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->ID ) .'" />';
$output .= '<input type="hidden" name="menu-item-object-id[]" id="menu-item-object-id'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->object_id ) .'" />';
@ -226,11 +226,11 @@ function wp_get_nav_menu_item( $menu_item, $context = 'frontend', $args = array(
$output .= '<input type="hidden" name="menu-item-attr-title[]" id="menu-item-attr-title'. esc_attr( $menu_item->menu_order ) .'" value="'.esc_attr( $menu_item->post_excerpt ) .'" />';
$output .= '<input type="hidden" name="menu-item-target[]" id="menu-item-target'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->target ) .'" />';
break;
case 'custom':
$menu_id = 'menu-item-' . $menu_item->db_id;
$output .= '<label class="menu-item-title"><input type="checkbox" id="'. esc_attr( $menu_id ) .'" name="'. esc_attr( $menu_item->title ) .'" value="'. esc_attr( $menu_item->url ) .'" />'. $menu_item->title .'</label>';
// Menu item hidden fields
$output .= '<input type="hidden" class="menu-item-db-id" value="'. esc_attr( $menu_item->db_id ) .'" />';
$output .= '<input type="hidden" class="menu-item-object-id" value="'. esc_attr( $menu_item->object_id ) .'" />';
@ -245,12 +245,12 @@ function wp_get_nav_menu_item( $menu_item, $context = 'frontend', $args = array(
$output .= '<input type="hidden" class="menu-item-classes" value="'. esc_attr( $menu_item->classes ) .'" />';
$output .= '<input type="hidden" class="menu-item-xfn" value="'. esc_attr( $menu_item->xfn ) .'" />';
break;
case 'taxonomy':
case 'post_type':
$menu_id = 'menu-item-' . $menu_item->db_id;
$output .= '<label class="menu-item-title"><input type="checkbox" id="'. esc_attr( $menu_id ) .'" name="'. esc_attr( $menu_item->title ) .'" value="'. esc_attr( $menu_item->url ) .'" />'. $menu_item->title .'</label>';
// Menu item hidden fields
$output .= '<input type="hidden" class="menu-item-db-id" value="0" />';
$output .= '<input type="hidden" class="menu-item-object-id" value="'. esc_attr( $menu_item->object_id ) .'" />';
@ -262,7 +262,7 @@ function wp_get_nav_menu_item( $menu_item, $context = 'frontend', $args = array(
$output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />';
break;
}
return $output;
}
?>