mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
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:
parent
78ba3b94b1
commit
f15cdc78cf
@ -509,7 +509,7 @@ var wpNavMenu;
|
||||
|
||||
attachTabsPanelListeners : function() {
|
||||
$('#menu-settings-column').bind('click', function(e) {
|
||||
var selectAreaMatch, activePanel, panelId, wrapper, items,
|
||||
var selectAreaMatch, panelId, wrapper, items,
|
||||
target = $(e.target);
|
||||
|
||||
if ( target.hasClass('nav-tab-link') ) {
|
||||
@ -679,6 +679,12 @@ var wpNavMenu;
|
||||
},
|
||||
|
||||
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
|
||||
api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } );
|
||||
return true;
|
||||
@ -759,9 +765,8 @@ var wpNavMenu;
|
||||
},
|
||||
|
||||
removeMenuItem : function(el) {
|
||||
el = $(el)
|
||||
var children = el.childMenuItems(),
|
||||
that = this;
|
||||
el = $(el);
|
||||
var children = el.childMenuItems();
|
||||
|
||||
el.addClass('deleting').fadeOut( 350 , function() {
|
||||
el.remove();
|
||||
|
File diff suppressed because one or more lines are too long
@ -149,11 +149,13 @@ $menu[59] = array( '', 'read', 'separator2', '', 'wp-menu-separator' );
|
||||
if ( current_user_can( 'switch_themes') ) {
|
||||
$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'][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 {
|
||||
$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'][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.
|
||||
|
@ -15,6 +15,9 @@ require_once( 'admin.php' );
|
||||
// Load all the nav menu interface functions
|
||||
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
|
||||
if ( ! current_user_can('edit_theme_options') )
|
||||
wp_die( __( 'Cheatin’ uh?' ) );
|
||||
@ -270,28 +273,29 @@ switch ( $action ) {
|
||||
case 'update':
|
||||
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
|
||||
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 ) {
|
||||
$_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => $new_menu_title) );
|
||||
if ( $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 ) ) {
|
||||
$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>';
|
||||
}
|
||||
if ( is_wp_error( $_nav_menu_selected_id ) ) {
|
||||
$messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
|
||||
} 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
|
||||
@ -425,8 +429,6 @@ require_once( 'admin-header.php' );
|
||||
echo $message . "\n";
|
||||
endforeach;
|
||||
?>
|
||||
|
||||
<?php if ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) : ?>
|
||||
<div id="nav-menus-frame">
|
||||
<div id="menu-settings-column" class="metabox-holder">
|
||||
|
||||
@ -517,7 +519,7 @@ require_once( 'admin-header.php' );
|
||||
</div><!--END #nav-menu-header-->
|
||||
<div id="post-body">
|
||||
<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">
|
||||
<?php
|
||||
$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-liquid -->
|
||||
</div><!-- /#nav-menus-frame-->
|
||||
<?php endif; // if menus supported in current theme ?>
|
||||
</div><!-- /.wrap-->
|
||||
|
||||
|
||||
|
@ -385,7 +385,7 @@ function wp_default_scripts( &$scripts ) {
|
||||
) );
|
||||
|
||||
// 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(
|
||||
'home' => _x('Home', 'nav menu home label'),
|
||||
'homeurl' => home_url('/'),
|
||||
|
Loading…
Reference in New Issue
Block a user