From 2010aac02c47e9fd5b346f5cd4d56d4e957817df Mon Sep 17 00:00:00 2001 From: nacin Date: Thu, 10 Jun 2010 17:37:15 +0000 Subject: [PATCH] Don't show an error when the theme supports widgets but not menus. see #13825. git-svn-id: http://svn.automattic.com/wordpress/trunk@15191 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/nav-menu.php | 9 ++++++++- wp-admin/nav-menus.php | 18 +++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index 624fb9fc6..a45b993e3 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -365,7 +365,7 @@ function _wp_ajax_menu_quick_search( $request = array() ) { **/ function wp_nav_menu_setup() { // Register meta boxes - if ( get_registered_nav_menus() && wp_get_nav_menus() ) + if ( ( current_theme_supports( 'widgets' ) || get_registered_nav_menus() ) && wp_get_nav_menus() ) add_meta_box( 'nav-menu-theme-locations', __( 'Theme Locations' ), 'wp_nav_menu_locations_meta_box' , 'nav-menus', 'side', 'default' ); add_meta_box( 'add-custom-links', __('Custom Links'), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); wp_nav_menu_post_type_meta_boxes(); @@ -461,6 +461,13 @@ function wp_nav_menu_taxonomy_meta_boxes() { function wp_nav_menu_locations_meta_box() { global $nav_menu_selected_id; $locations = get_registered_nav_menus(); + + if ( empty( $locations ) ) { + // We must only support widgets. Leave a message and bail. + echo '

' . __('The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.') . '

'; + return; + } + $menus = wp_get_nav_menus(); $menu_locations = get_nav_menu_locations(); $num_locations = count( array_keys($locations) ); diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php index 6e3407070..c56b84ac3 100644 --- a/wp-admin/nav-menus.php +++ b/wp-admin/nav-menus.php @@ -248,7 +248,7 @@ switch ( $action ) { } else { // Remove this menu from any locations. $locations = get_theme_mod( 'nav_menu_locations' ); - foreach ( $locations as $location => $menu_id ) { + foreach ( (array) $locations as $location => $menu_id ) { if ( $menu_id == $nav_menu_selected_id ) $locations[ $location ] = 0; } @@ -430,20 +430,12 @@ foreach( (array) $nav_menus as $key => $_nav_menu ) { $nav_menus[$key]->truncated_name = $_nav_menu->truncated_name; } -// The theme supports menus -if ( current_theme_supports('nav-menus') ) { - // Set up nav menu - wp_nav_menu_setup(); - -// The theme does not support menus but supports widgets -} elseif ( current_theme_supports('widgets') ) { - // Set up nav menu - wp_nav_menu_setup(); - $messages[] = '

' . __('The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.') . '

'; -} - +wp_nav_menu_setup(); wp_initial_nav_menu_meta_boxes(); +if ( ! get_registered_nav_menus() && ! wp_get_nav_menus() ) + echo '

' . __('The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.') . '

'; + $help = '

' . __('This feature is new in version 3.0; to use a custom menu in place of your theme’s default menus, support for this feature must be registered in the theme’s functions.php file. If your theme does not support the custom menus feature yet (the new default theme, Twenty Ten, does), you can learn about adding support yourself by following the below link.') . '

'; $help .= '

' . __('You can create custom menus for your site. These menus may contain links to pages, categories, custom links or other content types (use the Screen Options tab to decide which ones to show on the screen). You can specify a different navigation label for a menu item as well as other attributes. You can create multiple menus. If your theme includes more than one menu, you can choose which custom menu to associate with each. You can also use custom menus in conjunction with the Custom Menus widget.') . '

'; $help .= '

' . __('To create a new custom menu, click on the + tab, give the menu a name, and click Create Menu. Next, add menu items from the appropriate boxes. You’ll be able to edit the information for each menu item, and can drag and drop to put them in order. You can also drag a menu item a little to the right to make it a submenu, to create menus with hierarchy. You’ll see when the position of the drop target shifts over to create the nested placement. Don’t forget to click Save when you’re finished.') . '

';