First pass on 'Theme Locations' for navigation menus. Themes need to specify a location when calling wp_nav_menu and register locations in functions.php. Users then map menus to locations in the nav menu admin. Subject to review. see #13378.
git-svn-id: http://svn.automattic.com/wordpress/trunk@14620 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c1dea00b62
commit
a743de0788
File diff suppressed because one or more lines are too long
|
@ -197,7 +197,12 @@ body {
|
|||
.customlinkdiv .howto input {
|
||||
width: 210px;
|
||||
}
|
||||
|
||||
#nav-menu-theme-locations .howto select {
|
||||
width: 100%;
|
||||
}
|
||||
#nav-menu-theme-locations .button-controls {
|
||||
text-align: right;
|
||||
}
|
||||
.add-menu-item-view-all {
|
||||
height: 400px;
|
||||
}
|
||||
|
|
|
@ -308,6 +308,7 @@ function _wp_ajax_menu_quick_search( $request = array() ) {
|
|||
**/
|
||||
function wp_nav_menu_setup() {
|
||||
// Register meta boxes
|
||||
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();
|
||||
wp_nav_menu_taxonomy_meta_boxes();
|
||||
|
@ -337,7 +338,7 @@ function wp_initial_nav_menu_meta_boxes() {
|
|||
if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array($wp_meta_boxes) )
|
||||
return;
|
||||
|
||||
$initial_meta_boxes = array( 'manage-menu', 'create-menu', 'add-custom-links', 'add-page', 'add-category' );
|
||||
$initial_meta_boxes = array( 'nav-menu-theme-locations', 'add-custom-links', 'add-page', 'add-category' );
|
||||
$hidden_meta_boxes = array();
|
||||
|
||||
foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) {
|
||||
|
@ -396,6 +397,41 @@ function wp_nav_menu_taxonomy_meta_boxes() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a metabox for the nav menu theme locations.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
function wp_nav_menu_locations_meta_box() {
|
||||
$locations = get_registered_nav_menus();
|
||||
$mods = get_nav_menu_locations();
|
||||
$menus = wp_get_nav_menus();
|
||||
$menu_locations = get_nav_menu_locations();
|
||||
//var_dump( $menus );
|
||||
foreach ( $locations as $location => $description ) {
|
||||
?>
|
||||
<p>
|
||||
<label class="howto" for="locations-<?php echo $location; ?>">
|
||||
<span><?php echo $description; ?></span>
|
||||
<select name="menu-locations[<?php echo $location; ?>]" id="locations-<?php echo $location; ?>">
|
||||
<option value=""></option>
|
||||
<?php foreach ( $menus as $menu ) : ?>
|
||||
<option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?>
|
||||
value="<?php echo $menu->term_id; ?>"><?php echo $menu->name; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<p class="button-controls">
|
||||
<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
|
||||
<input type="submit" class="button-primary" name="nav-menu-locations" value="<?php esc_attr_e( 'Save' ); ?>" />
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a metabox for the custom links menu item.
|
||||
*
|
||||
|
|
|
@ -52,7 +52,9 @@ $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
|
|||
switch ( $action ) {
|
||||
case 'add-menu-item':
|
||||
check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
|
||||
if ( isset( $_REQUEST['menu-item'] ) )
|
||||
if ( isset( $_REQUEST['nav-menu-locations'] ) )
|
||||
set_theme_mod( 'nav_menu_locations', $_REQUEST['menu-locations'] );
|
||||
elseif ( isset( $_REQUEST['menu-item'] ) )
|
||||
wp_save_nav_menu_item( $nav_menu_selected_id, $_REQUEST['menu-item'] );
|
||||
break;
|
||||
case 'move-down-menu-item' :
|
||||
|
|
|
@ -79,9 +79,6 @@ function twentyten_setup() {
|
|||
// This theme uses post thumbnails
|
||||
add_theme_support( 'post-thumbnails' );
|
||||
|
||||
// This theme uses wp_nav_menu()
|
||||
register_nav_menus( array('main' => __('Main Menu')) );
|
||||
|
||||
// Add default posts and comments RSS feed links to head
|
||||
add_theme_support( 'automatic-feed-links' );
|
||||
|
||||
|
@ -94,6 +91,11 @@ function twentyten_setup() {
|
|||
if ( is_readable( $locale_file ) )
|
||||
require_once( $locale_file );
|
||||
|
||||
// This theme uses wp_nav_menu() in one location.
|
||||
register_nav_menus( array(
|
||||
'primary' => __( 'Primary Menu', 'twentyten' ),
|
||||
) );
|
||||
|
||||
// This theme allows users to set a custom background
|
||||
add_custom_background();
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
|
||||
<div id="access" role="navigation">
|
||||
<div class="skip-link screen-reader-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentyten' ); ?>"><?php _e( 'Skip to content', 'twentyten' ); ?></a></div>
|
||||
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header', 'theme_menu' => 'main' ) ); ?>
|
||||
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>
|
||||
</div><!-- #access -->
|
||||
</div><!-- #masthead -->
|
||||
</div><!-- #header -->
|
||||
|
|
|
@ -193,23 +193,20 @@ 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', 'theme_menu' => '' );
|
||||
'depth' => 0, 'walker' => '', 'context' => 'frontend', 'theme_location' => '' );
|
||||
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
$args = apply_filters( 'wp_nav_menu_args', $args );
|
||||
$args = (object) $args;
|
||||
|
||||
// Get the nav menu
|
||||
// Get the nav menu based on the requested 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'] );
|
||||
}
|
||||
// Get the nav menu based on the theme_location
|
||||
if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) )
|
||||
$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
|
||||
|
||||
// If we couldn't find a menu based off the menu argument
|
||||
// get the first menu that has items.
|
||||
// get the first menu that has items if we still can't find a menu
|
||||
if ( ! $menu ) {
|
||||
$menus = wp_get_nav_menus();
|
||||
foreach ( $menus as $menu_maybe ) {
|
||||
|
|
|
@ -66,24 +66,34 @@ function is_nav_menu( $menu ) {
|
|||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param array Associative array of menu slot identifiers and descriptions.
|
||||
* @param array $locations Associative array of menu location identifiers (like a slug) and descriptive text.
|
||||
*/
|
||||
function register_nav_menus( $menus = array() ) {
|
||||
function register_nav_menus( $locations = array() ) {
|
||||
global $_wp_registered_nav_menus;
|
||||
|
||||
add_theme_support( 'nav-menus' );
|
||||
|
||||
$_wp_registered_nav_menus = $menus;
|
||||
$_wp_registered_nav_menus = array_merge( (array) $_wp_registered_nav_menus, $locations );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register nav menu for a theme.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $location Menu location identifier, like a slug.
|
||||
* @param string $description Menu location descriptive text.
|
||||
*/
|
||||
function register_nav_menu( $location, $description ) {
|
||||
register_nav_menus( array( $location => $description ) );
|
||||
}
|
||||
|
||||
function get_registered_nav_menus() {
|
||||
global $_wp_registered_nav_menus;
|
||||
|
||||
return $_wp_registered_nav_menus;
|
||||
return $GLOBALS['_wp_registered_nav_menus'];
|
||||
}
|
||||
|
||||
function get_nav_menu_slots() {
|
||||
return get_theme_mod('nav_menu_slots');
|
||||
function get_nav_menu_locations() {
|
||||
return get_theme_mod('nav_menu_locations');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -476,7 +476,7 @@ function wp_default_styles( &$styles ) {
|
|||
$styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.2' );
|
||||
$styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.css', array(), '0.9.8' );
|
||||
$styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.1' );
|
||||
$styles->add( 'nav-menu', "/wp-admin/css/nav-menu$suffix.css", array(), '20100512' );
|
||||
$styles->add( 'nav-menu', "/wp-admin/css/nav-menu$suffix.css", array(), '20100514' );
|
||||
|
||||
foreach ( $rtl_styles as $rtl_style ) {
|
||||
$styles->add_data( $rtl_style, 'rtl', true );
|
||||
|
|
Loading…
Reference in New Issue