Menu tweaks. Save menu locations when saving the menu. Also, centralize theme support checks and add them to menu.php. Improve some branching. Remove some old JS vars, add a missing semicolon, etc. props koopersmith. see #13378.

git-svn-id: http://svn.automattic.com/wordpress/trunk@14831 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-05-24 09:23:56 +00:00
parent 78ba3b94b1
commit f15cdc78cf
5 changed files with 36 additions and 28 deletions

View File

@ -509,7 +509,7 @@ var wpNavMenu;
attachTabsPanelListeners : function() { attachTabsPanelListeners : function() {
$('#menu-settings-column').bind('click', function(e) { $('#menu-settings-column').bind('click', function(e) {
var selectAreaMatch, activePanel, panelId, wrapper, items, var selectAreaMatch, panelId, wrapper, items,
target = $(e.target); target = $(e.target);
if ( target.hasClass('nav-tab-link') ) { if ( target.hasClass('nav-tab-link') ) {
@ -679,6 +679,12 @@ var wpNavMenu;
}, },
eventOnClickMenuSave : function(clickedEl) { eventOnClickMenuSave : function(clickedEl) {
var locs = '';
// Copy menu theme locations
$('#nav-menu-theme-locations select').each(function() {
locs += '<input type="hidden" name="' + this.name + '" value="' + $(this).val() + '" />';
});
$('#update-nav-menu').append( locs );
// Update menu item position data // Update menu item position data
api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } ); api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } );
return true; return true;
@ -759,9 +765,8 @@ var wpNavMenu;
}, },
removeMenuItem : function(el) { removeMenuItem : function(el) {
el = $(el) el = $(el);
var children = el.childMenuItems(), var children = el.childMenuItems();
that = this;
el.addClass('deleting').fadeOut( 350 , function() { el.addClass('deleting').fadeOut( 350 , function() {
el.remove(); el.remove();

File diff suppressed because one or more lines are too long

View File

@ -149,11 +149,13 @@ $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' );
if ( current_user_can( 'switch_themes') ) { if ( current_user_can( 'switch_themes') ) {
$menu[60] = array( __('Appearance'), 'switch_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' ); $menu[60] = array( __('Appearance'), 'switch_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' );
$submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php'); $submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php');
$submenu['themes.php'][10] = array(__('Menus'), 'edit_theme_options', 'nav-menus.php'); if ( current_theme_supports( 'nav-menus' ) || current_theme_supports( 'widgets' ) )
$submenu['themes.php'][10] = array(__('Menus'), 'edit_theme_options', 'nav-menus.php');
} else { } else {
$menu[60] = array( __('Appearance'), 'edit_theme_options', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' ); $menu[60] = array( __('Appearance'), 'edit_theme_options', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' );
$submenu['themes.php'][5] = array(__('Themes'), 'edit_theme_options', 'themes.php'); $submenu['themes.php'][5] = array(__('Themes'), 'edit_theme_options', 'themes.php');
$submenu['themes.php'][10] = array(__('Menus'), 'edit_theme_options', 'nav-menus.php' ); if ( current_theme_supports( 'nav-menus' ) || current_theme_supports( 'widgets' ) )
$submenu['themes.php'][10] = array(__('Menus'), 'edit_theme_options', 'nav-menus.php' );
} }
// Add 'Editor' to the bottom of the Appearence menu. // Add 'Editor' to the bottom of the Appearence menu.

View File

@ -15,6 +15,9 @@ require_once( 'admin.php' );
// Load all the nav menu interface functions // Load all the nav menu interface functions
require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' ); require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
if ( ! current_theme_supports( 'nav-menus' ) && ! current_theme_supports( 'widgets' ) )
wp_die( __( 'Your theme does not support navigation menus or widgets.' ) );
// Permissions Check // Permissions Check
if ( ! current_user_can('edit_theme_options') ) if ( ! current_user_can('edit_theme_options') )
wp_die( __( 'Cheatin&#8217; uh?' ) ); wp_die( __( 'Cheatin&#8217; uh?' ) );
@ -270,28 +273,29 @@ switch ( $action ) {
case 'update': case 'update':
check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
// Update menu theme locations
set_theme_mod( 'nav_menu_locations', $_POST['menu-locations'] );
// Add Menu // Add Menu
if ( 0 == $nav_menu_selected_id ) { if ( 0 == $nav_menu_selected_id ) {
if ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) { $new_menu_title = esc_html( $_POST['menu-name'] );
$new_menu_title = esc_html( $_POST['menu-name'] );
if ( $new_menu_title ) { if ( $new_menu_title ) {
$_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => $new_menu_title) ); $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => $new_menu_title) );
if ( is_wp_error( $_nav_menu_selected_id ) ) { if ( is_wp_error( $_nav_menu_selected_id ) ) {
$messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>'; $messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
} else {
if ( ( $_menu_locations = get_registered_nav_menus() ) && 1 == count( wp_get_nav_menus() ) )
set_theme_mod( 'nav_menu_locations', array( key( $_menu_locations ) => $_nav_menu_selected_id ) );
unset( $_menu_locations );
$_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
$nav_menu_selected_id = $_nav_menu_selected_id;
$nav_menu_selected_title = $_menu_object->name;
$messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), $nav_menu_selected_title ) . '</p></div>';
}
} else { } else {
$messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>'; if ( ( $_menu_locations = get_registered_nav_menus() ) && 1 == count( wp_get_nav_menus() ) )
set_theme_mod( 'nav_menu_locations', array( key( $_menu_locations ) => $_nav_menu_selected_id ) );
unset( $_menu_locations );
$_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
$nav_menu_selected_id = $_nav_menu_selected_id;
$nav_menu_selected_title = $_menu_object->name;
$messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), $nav_menu_selected_title ) . '</p></div>';
} }
} else {
$messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>';
} }
// update existing menu // update existing menu
@ -425,8 +429,6 @@ require_once( 'admin-header.php' );
echo $message . "\n"; echo $message . "\n";
endforeach; endforeach;
?> ?>
<?php if ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) : ?>
<div id="nav-menus-frame"> <div id="nav-menus-frame">
<div id="menu-settings-column" class="metabox-holder"> <div id="menu-settings-column" class="metabox-holder">
@ -517,7 +519,7 @@ require_once( 'admin-header.php' );
</div><!--END #nav-menu-header--> </div><!--END #nav-menu-header-->
<div id="post-body"> <div id="post-body">
<div id="post-body-content"> <div id="post-body-content">
<?php if ( is_nav_menu( $nav_menu_selected_id ) && ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) ) : ?> <?php if ( is_nav_menu( $nav_menu_selected_id ) ) : ?>
<ul class="menu" id="menu-to-edit"> <ul class="menu" id="menu-to-edit">
<?php <?php
$edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id ); $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id );
@ -542,7 +544,6 @@ require_once( 'admin-header.php' );
</div><!-- /#menu-management --> </div><!-- /#menu-management -->
</div><!-- /#menu-management-liquid --> </div><!-- /#menu-management-liquid -->
</div><!-- /#nav-menus-frame--> </div><!-- /#nav-menus-frame-->
<?php endif; // if menus supported in current theme ?>
</div><!-- /.wrap--> </div><!-- /.wrap-->

View File

@ -385,7 +385,7 @@ function wp_default_scripts( &$scripts ) {
) ); ) );
// Custom Navigation // Custom Navigation
$scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100521' ); $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100524' );
$scripts->localize( 'nav-menu', 'navMenuL10n', array( $scripts->localize( 'nav-menu', 'navMenuL10n', array(
'home' => _x('Home', 'nav menu home label'), 'home' => _x('Home', 'nav menu home label'),
'homeurl' => home_url('/'), 'homeurl' => home_url('/'),