mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Move nav menus to a tabbed interface, so that users with a lot of locations can do bulk assignment.
props DrewAPicture, lessbloat. fixes #23770 git-svn-id: http://core.svn.wordpress.org/trunk@23810 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
98c3cf6e4b
commit
19810a259c
@ -697,6 +697,9 @@ form.upgrade .hint {
|
||||
.fixed .column-comments a {
|
||||
float: right;
|
||||
}
|
||||
.fixed .column-menus {
|
||||
text-align: right;
|
||||
}
|
||||
.sorting-indicator {
|
||||
margin-left: 0;
|
||||
margin-right: 7px;
|
||||
@ -2083,6 +2086,27 @@ body.login {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.menu-location-menus select {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.locations-row-links {
|
||||
float: right;
|
||||
margin: 4px 6px 0 0;
|
||||
}
|
||||
|
||||
.locations-add-menu-link {
|
||||
direction: rtl;
|
||||
}
|
||||
|
||||
.locations-edit-menu-link {
|
||||
border-left: 1px solid #CCCCCC;
|
||||
border-right: 0;
|
||||
padding-left: 6px;
|
||||
padding-right: 0;
|
||||
float: right;
|
||||
}
|
||||
|
||||
/* Menu Container */
|
||||
#menu-management-liquid {
|
||||
float: right;
|
||||
|
@ -2423,6 +2423,7 @@ table.fixed {
|
||||
width: 8%;
|
||||
}
|
||||
|
||||
.fixed .column-posts,
|
||||
.fixed .column-date,
|
||||
.fixed .column-parent,
|
||||
.fixed .column-links,
|
||||
@ -2439,6 +2440,14 @@ table.fixed {
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
.fixed .column-slug {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.fixed .column-locations {
|
||||
width: 35%;
|
||||
}
|
||||
|
||||
.fixed .column-comments {
|
||||
width: 4em;
|
||||
padding: 8px 0;
|
||||
@ -2453,14 +2462,6 @@ table.fixed {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.fixed .column-slug {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.fixed .column-posts {
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
.fixed .column-icon {
|
||||
width: 80px;
|
||||
}
|
||||
@ -2547,6 +2548,10 @@ tr.wp-locked .row-actions .trash {
|
||||
margin-top: 3px;
|
||||
}
|
||||
|
||||
#menu-locations-wrap .widefat {
|
||||
width: 60%;
|
||||
}
|
||||
|
||||
.widefat th.sortable,
|
||||
.widefat th.sorted {
|
||||
padding: 0;
|
||||
@ -7384,7 +7389,7 @@ body.interim-login {
|
||||
|
||||
#nav-menus-frame {
|
||||
margin-left: 300px;
|
||||
margin-top: 28px;
|
||||
margin-top: 23px;
|
||||
}
|
||||
|
||||
#wpbody-content #menu-settings-column {
|
||||
@ -7401,7 +7406,8 @@ body.interim-login {
|
||||
margin: 10px 0 0;
|
||||
}
|
||||
|
||||
.metabox-holder-disabled .postbox {
|
||||
.metabox-holder-disabled .postbox,
|
||||
.metabox-holder-disabled .accordion-section-content {
|
||||
opacity: 0.5;
|
||||
filter: alpha(opacity=50);
|
||||
}
|
||||
@ -7432,7 +7438,7 @@ body.interim-login {
|
||||
}
|
||||
|
||||
.manage-menus {
|
||||
margin-top: 13px;
|
||||
margin-top: 23px;
|
||||
padding: 10px;
|
||||
overflow: hidden;
|
||||
-webkit-border-radius: 3px;
|
||||
@ -7566,6 +7572,39 @@ body.interim-login {
|
||||
margin-top: -2px;
|
||||
}
|
||||
|
||||
.widefat td.menu-location-menus {
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
.menu-location-menus select {
|
||||
float: left;
|
||||
}
|
||||
|
||||
#locations-nav-menu-wrapper {
|
||||
padding: 5px 0;
|
||||
}
|
||||
|
||||
.locations-nav-menu-select select {
|
||||
float: left;
|
||||
width: 160px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.locations-row-links {
|
||||
float: left;
|
||||
margin: 6px 0 0 6px;
|
||||
}
|
||||
|
||||
.locations-edit-menu-link,
|
||||
.locations-add-menu-link {
|
||||
margin: 0 3px;
|
||||
}
|
||||
|
||||
.locations-edit-menu-link {
|
||||
padding-right: 3px;
|
||||
border-right: 1px solid #ccc;
|
||||
}
|
||||
|
||||
#wpbody .open-label {
|
||||
display: block;
|
||||
float:left;
|
||||
|
@ -48,6 +48,8 @@ var wpNavMenu;
|
||||
if ( menus.oneThemeLocationNoMenus )
|
||||
$( '#posttype-page' ).addSelectedToMenu( api.addMenuItemToBottom );
|
||||
|
||||
this.initManageLocations();
|
||||
|
||||
this.initAccessibility();
|
||||
|
||||
this.initToggles();
|
||||
@ -735,6 +737,19 @@ var wpNavMenu;
|
||||
}
|
||||
},
|
||||
|
||||
initManageLocations : function () {
|
||||
$('#menu-locations-wrap form').submit(function(){
|
||||
window.onbeforeunload = null;
|
||||
});
|
||||
$('.menu-location-menus select').on('change', function () {
|
||||
var editLink = $(this).closest('tr').find('.locations-edit-menu-link');
|
||||
if ($(this).find('option:selected').data('orig'))
|
||||
editLink.show();
|
||||
else
|
||||
editLink.hide();
|
||||
});
|
||||
},
|
||||
|
||||
attachMenuEditListeners : function() {
|
||||
var that = this;
|
||||
$('#update-nav-menu').bind('click', function(e) {
|
||||
@ -927,11 +942,11 @@ var wpNavMenu;
|
||||
},
|
||||
|
||||
attachUnsavedChangesListener : function() {
|
||||
$('#menu-management input, #menu-management select, #menu-management, #menu-management textarea').change(function(){
|
||||
$('#menu-management input, #menu-management select, #menu-management, #menu-management textarea, .menu-location-menus select').change(function(){
|
||||
api.registerChange();
|
||||
});
|
||||
|
||||
if ( 0 != $('#menu-to-edit').length ) {
|
||||
if ( 0 != $('#menu-to-edit').length || 0 != $('.menu-location-menus select').length ) {
|
||||
window.onbeforeunload = function(){
|
||||
if ( api.menusChanged )
|
||||
return navMenuL10n.saveAlert;
|
||||
|
@ -37,6 +37,11 @@ $nav_menu_selected_title = '';
|
||||
// The menu id of the current menu being edited
|
||||
$nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
|
||||
|
||||
// Get existing menu locations assignments
|
||||
$locations = get_registered_nav_menus();
|
||||
$menu_locations = get_nav_menu_locations();
|
||||
$num_locations = count( array_keys( $locations ) );
|
||||
|
||||
// Allowed actions: add, update, delete
|
||||
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
|
||||
|
||||
@ -262,10 +267,6 @@ switch ( $action ) {
|
||||
case 'update':
|
||||
check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
|
||||
|
||||
// Get existing menu locations assignments
|
||||
$locations = get_registered_nav_menus();
|
||||
$menu_locations = get_nav_menu_locations();
|
||||
|
||||
// Remove menu locations that have been unchecked
|
||||
foreach ( $locations as $location => $description ) {
|
||||
if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) ) && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id )
|
||||
@ -307,7 +308,15 @@ switch ( $action ) {
|
||||
}
|
||||
set_theme_mod( 'nav_menu_locations', $locations );
|
||||
}
|
||||
$messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%s</strong> has been created.' ), $nav_menu_selected_title ) . '</p></div>';
|
||||
if ( isset( $_REQUEST['use-location'] ) ) {
|
||||
$locations = get_theme_mod( 'nav_menu_locations' );
|
||||
if ( isset( $locations[$_REQUEST['use-location']] ) )
|
||||
$locations[$_REQUEST['use-location']] = $nav_menu_selected_id;
|
||||
set_theme_mod( 'nav_menu_locations', $locations );
|
||||
}
|
||||
// $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%s</strong> has been created.' ), $nav_menu_selected_title ) . '</p></div>';
|
||||
wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) );
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
$messages[] = '<div id="message" class="error"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
|
||||
@ -341,6 +350,20 @@ switch ( $action ) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'locations':
|
||||
add_filter( 'screen_options_show_screen', '__return_false' );
|
||||
|
||||
if ( isset( $_POST['menu-locations'] ) ) {
|
||||
check_admin_referer( 'save-menu-locations' );
|
||||
|
||||
$new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
|
||||
$menu_locations = array_merge( $menu_locations, $new_menu_locations );
|
||||
// Set menu locations
|
||||
set_theme_mod( 'nav_menu_locations', $menu_locations );
|
||||
|
||||
$messages[] = '<div id="message" class="updated"><p>' . __( 'Menu locations updated.' ) . '</p></div>';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Get all nav menus
|
||||
@ -350,6 +373,8 @@ $menu_count = count( $nav_menus );
|
||||
// Are we on the add new screen?
|
||||
$add_new_screen = ( isset( $_GET['menu'] ) && 0 == $_GET['menu'] ) ? true : false;
|
||||
|
||||
$locations_screen = ( isset( $_GET['action'] ) && 'locations' == $_GET['action'] ) ? true : false;
|
||||
|
||||
// If we have one theme location, and zero menus, we take them right into editing their first menu
|
||||
$page_count = wp_count_posts( 'page' );
|
||||
$one_theme_location_no_menus = ( 1 == count( get_registered_nav_menus() ) && ! $add_new_screen && empty( $nav_menus ) && ! empty( $page_count->publish ) ) ? true : false;
|
||||
@ -474,19 +499,82 @@ require_once( './admin-header.php' );
|
||||
?>
|
||||
<div class="wrap">
|
||||
<?php screen_icon(); ?>
|
||||
<h2><?php _e( 'Menus' ); ?> <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0, ), admin_url( 'nav-menus.php' ) ) ); ?>" class="add-new-h2"><?php _ex( 'Add New', 'menu' ); ?></a></h2>
|
||||
<h2 class="nav-tab-wrapper">
|
||||
<a href="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-tab<?php if ( ! isset( $_GET['action'] ) || isset( $_GET['action'] ) && 'locations' != $_GET['action'] ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Edit Menus' ); ?></a>
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>" class="nav-tab<?php if ( $locations_screen ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Manage Locations' ); ?></a>
|
||||
</h2>
|
||||
<?php
|
||||
foreach( $messages as $message ) :
|
||||
echo $message . "\n";
|
||||
endforeach;
|
||||
?>
|
||||
<?php
|
||||
if ( $locations_screen ) :
|
||||
echo '<p>' . sprintf( _n( 'Your theme supports %s menu. Select which menu you would like to use below.', 'Your theme supports %s menus. Select a menu to use for each theme location below.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>';
|
||||
?>
|
||||
<div id="menu-locations-wrap">
|
||||
<form method="post" action="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>">
|
||||
<table class="widefat fixed" cellspacing="0" id="menu-locations-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th>
|
||||
<th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<!--<tfoot>
|
||||
<tr>
|
||||
<th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th>
|
||||
<th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th>
|
||||
</tr>
|
||||
</tfoot>-->
|
||||
<tbody class="menu-locations">
|
||||
<?php foreach ( $locations as $_location => $_name ) { ?>
|
||||
<tr id="menu-locations-row">
|
||||
<td class="menu-location-title"><strong><?php echo $_name; ?></strong></td>
|
||||
<td class="menu-location-menus">
|
||||
<select name="menu-locations[<?php echo $_location; ?>]" id="locations-<?php echo $_location; ?>">
|
||||
<option value="0"><?php printf( '— %s —', esc_html__( 'Select a Menu' ) ); ?></option>
|
||||
<?php foreach ( $nav_menus as $menu ) : ?>
|
||||
<?php $selected = isset( $menu_locations[$_location] ) && $menu_locations[$_location] == $menu->term_id; ?>
|
||||
<option <?php if ( $selected ) echo 'data-orig="true"'; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>">
|
||||
<?php $truncated_name = wp_html_excerpt( $menu->name, 40 );
|
||||
echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '…'; ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<div class="locations-row-links">
|
||||
<?php if ( isset( $menu_locations[ $_location ] ) && 0 != $menu_locations[ $_location ] ) : ?>
|
||||
<span class="locations-edit-menu-link">
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => $menu_locations[$_location] ), admin_url( 'nav-menus.php' ) ) ); ?>">
|
||||
<?php _ex( 'Edit', 'menu' ); ?>
|
||||
</a>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<span class="locations-add-menu-link">
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0, 'use-location' => $_location ), admin_url( 'nav-menus.php' ) ) ); ?>">
|
||||
<?php _ex( 'Use new menu', 'menu' ); ?>
|
||||
</a>
|
||||
</span>
|
||||
</div><!-- #locations-row-links -->
|
||||
</td><!-- .menu-location-menus -->
|
||||
</tr><!-- #menu-locations-row -->
|
||||
<?php } // foreach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="button-controls"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p>
|
||||
<?php wp_nonce_field( 'save-menu-locations' ); ?>
|
||||
<input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
|
||||
</form>
|
||||
</div><!-- #menu-locations-wrap -->
|
||||
<?php do_action( 'after_menu_locations_table' ); ?>
|
||||
<?php else : ?>
|
||||
<div class="manage-menus">
|
||||
<?php if ( $menu_count < 2 ) : ?>
|
||||
<?php if ( $menu_count < 2 ) : ?>
|
||||
<span class="add-edit-menu-action">
|
||||
<?php printf( __( 'Edit your menu below, or <a href="%s">create a new menu</a>.' ), esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0 ), admin_url( 'nav-menus.php' ) ) ) ); ?>
|
||||
</span><!-- /add-edit-menu-action -->
|
||||
<?php else : ?>
|
||||
<form method="get" action="">
|
||||
<?php else : ?>
|
||||
<form method="get" action="<?php echo admin_url( 'nav-menus.php' ); ?>">
|
||||
<input type="hidden" name="action" value="edit" />
|
||||
<label for="menu" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label>
|
||||
<select name="menu" id="menu">
|
||||
@ -578,6 +666,9 @@ require_once( './admin-header.php' );
|
||||
<?php endif; ?>
|
||||
<?php if ( $add_new_screen ) : ?>
|
||||
<p class="post-body-plain"><?php _e( 'Give your menu a name above, then click Create Menu.' ); ?></p>
|
||||
<?php if ( isset( $_GET['use-location'] ) ) : ?>
|
||||
<input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" />
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<div class="menu-settings" <?php if ( $one_theme_location_no_menus ) { ?>style="display: none;"<?php } ?>>
|
||||
<h3><?php _e( 'Menu Settings' ); ?></h3>
|
||||
@ -633,5 +724,6 @@ require_once( './admin-header.php' );
|
||||
</div><!-- /#menu-management -->
|
||||
</div><!-- /#menu-management-liquid -->
|
||||
</div><!-- /#nav-menus-frame -->
|
||||
<?php endif; ?>
|
||||
</div><!-- /.wrap-->
|
||||
<?php include( './admin-footer.php' ); ?>
|
||||
|
Loading…
Reference in New Issue
Block a user