From 21bef33fc6a46694a77cbbb3e62d7a1d9ca732da Mon Sep 17 00:00:00 2001 From: wpmuguru Date: Thu, 13 May 2010 22:14:54 +0000 Subject: [PATCH] add menu slots/theme_menus, props ryan, see #13378 git-svn-id: http://svn.automattic.com/wordpress/trunk@14611 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/nav-menus.php | 13 +++++++++++- wp-content/themes/twentyten/functions.php | 2 +- wp-content/themes/twentyten/header.php | 2 +- wp-includes/nav-menu-template.php | 8 +++++++- wp-includes/nav-menu.php | 25 +++++++++++++++++++++++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php index 31123f6cd..7bbf1e840 100644 --- a/wp-admin/nav-menus.php +++ b/wp-admin/nav-menus.php @@ -482,7 +482,18 @@ require_once( 'admin-header.php' );
- + + +
diff --git a/wp-content/themes/twentyten/functions.php b/wp-content/themes/twentyten/functions.php index 06b44d0ea..67bb4edd0 100644 --- a/wp-content/themes/twentyten/functions.php +++ b/wp-content/themes/twentyten/functions.php @@ -80,7 +80,7 @@ function twentyten_setup() { add_theme_support( 'post-thumbnails' ); // This theme uses wp_nav_menu() - add_theme_support( 'nav-menus' ); + register_nav_menus( array('main' => __('Main Menu')) ); // Add default posts and comments RSS feed links to head add_theme_support( 'automatic-feed-links' ); diff --git a/wp-content/themes/twentyten/header.php b/wp-content/themes/twentyten/header.php index 97f743e23..c789ddc74 100644 --- a/wp-content/themes/twentyten/header.php +++ b/wp-content/themes/twentyten/header.php @@ -69,7 +69,7 @@ diff --git a/wp-includes/nav-menu-template.php b/wp-includes/nav-menu-template.php index 52cefa243..f73e90c60 100644 --- a/wp-includes/nav-menu-template.php +++ b/wp-includes/nav-menu-template.php @@ -193,7 +193,7 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { function wp_nav_menu( $args = array() ) { $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', - 'depth' => 0, 'walker' => '', 'context' => 'frontend' ); + 'depth' => 0, 'walker' => '', 'context' => 'frontend', 'theme_menu' => '' ); $args = wp_parse_args( $args, $defaults ); $args = apply_filters( 'wp_nav_menu_args', $args ); @@ -202,6 +202,12 @@ function wp_nav_menu( $args = array() ) { // Get the nav menu $menu = wp_get_nav_menu_object( $args->menu ); + if ( ! $menu && $slot ) { + $slots = get_nav_menu_slots(); + if ( isset($slots) && isset($slots['theme_menu']) ) + $menu = wp_get_nav_menu_object( $slots['theme_menu'] ); + } + // If we couldn't find a menu based off the menu argument // get the first menu that has items. if ( ! $menu ) { diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index c087f3ff3..2a6cdd9e2 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -61,6 +61,31 @@ function is_nav_menu( $menu ) { return false; } +/** + * Register nav menus for a theme. + * + * @since 3.0.0 + * + * @param array Associative array of menu slot identifiers and descriptions. + */ +function register_nav_menus( $menus = array() ) { + global $_wp_registered_nav_menus; + + add_theme_support( 'nav-menus' ); + + $_wp_registered_nav_menus = $menus; +} + +function get_registered_nav_menus() { + global $_wp_registered_nav_menus; + + return $_wp_registered_nav_menus; +} + +function get_nav_menu_slots() { + return get_theme_mod('nav_menu_slots'); +} + /** * Determine whether the given ID is a nav menu item. *