Skip to content

Commit 5cb5488

Browse files
committed
Menus: Provide menu settings when creating a new menu.
This simplifies the steps in the process of adding new menus. Props: garrett-eclipse, audrasjb, ianjvr. git-svn-id: https://develop.svn.wordpress.org/trunk@48051 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1d5e59c commit 5cb5488

2 files changed

Lines changed: 21 additions & 30 deletions

File tree

src/wp-admin/css/nav-menus.css

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ ul.add-menu-item-tabs li {
6565
position: relative;
6666
}
6767

68-
.blank-slate .menu-settings {
69-
border: none;
70-
margin-top: 0;
71-
padding-top: 0;
72-
overflow: hidden;
73-
}
74-
7568
.is-submenu {
7669
color: #555d66; /* #fafafa background */
7770
font-style: italic;
@@ -749,10 +742,6 @@ body.menu-max-depth-11 { min-width: 1280px !important; }
749742
float: right;
750743
}
751744

752-
.nav-menus-php .blank-slate .menu-settings {
753-
display: none;
754-
}
755-
756745
/* Same as the Publish Meta Box #delete-action */
757746
.nav-menus-php .delete-action {
758747
float: left;

src/wp-admin/nav-menus.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -300,22 +300,12 @@
300300
case 'update':
301301
check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
302302

303-
// Remove menu locations that have been unchecked.
304-
foreach ( $locations as $location => $description ) {
305-
if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) ) && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id ) {
306-
unset( $menu_locations[ $location ] );
307-
}
308-
}
309-
310303
// Merge new and existing menu locations if any new ones are set.
311304
if ( isset( $_POST['menu-locations'] ) ) {
312305
$new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
313306
$menu_locations = array_merge( $menu_locations, $new_menu_locations );
314307
}
315308

316-
// Set menu locations.
317-
set_theme_mod( 'nav_menu_locations', $menu_locations );
318-
319309
// Add Menu.
320310
if ( 0 == $nav_menu_selected_id ) {
321311
$new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
@@ -332,9 +322,18 @@
332322
if ( isset( $_REQUEST['menu-item'] ) ) {
333323
wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) );
334324
}
335-
if ( isset( $_REQUEST['zero-menu-state'] ) ) {
325+
// Set the menu_location value correctly for the newly created menu.
326+
foreach ( $menu_locations as $location => $id ) {
327+
if ( 0 === $id ) {
328+
$menu_locations[ $location ] = $nav_menu_selected_id;
329+
}
330+
}
331+
set_theme_mod( 'nav_menu_locations', $menu_locations );
332+
if ( isset( $_REQUEST['zero-menu-state'] ) || ! empty( $_POST['auto-add-pages'] ) ) {
336333
// If there are menu items, add them.
337334
wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title );
335+
}
336+
if ( isset( $_REQUEST['zero-menu-state'] ) ) {
338337
// Auto-save nav_menu_locations.
339338
$locations = get_nav_menu_locations();
340339
foreach ( $locations as $location => $menu_id ) {
@@ -359,8 +358,17 @@
359358
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
360359
}
361360

362-
// Update existing menu.
361+
// Update existing menu.
363362
} else {
363+
// Remove menu locations that have been unchecked.
364+
foreach ( $locations as $location => $description ) {
365+
if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) ) && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id ) {
366+
unset( $menu_locations[ $location ] );
367+
}
368+
}
369+
370+
// Set menu locations.
371+
set_theme_mod( 'nav_menu_locations', $menu_locations );
364372

365373
$_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
366374

@@ -893,14 +901,8 @@ function wp_nav_menu_max_depth( $classes ) {
893901
<div id="menu-management-liquid">
894902
<div id="menu-management">
895903
<form id="update-nav-menu" method="post" enctype="multipart/form-data">
896-
<?php
897-
$new_screen_class = '';
898-
if ( $add_new_screen ) {
899-
$new_screen_class = 'blank-slate';
900-
}
901-
?>
902904
<h2><?php _e( 'Menu structure' ); ?></h2>
903-
<div class="menu-edit <?php echo $new_screen_class; ?>">
905+
<div class="menu-edit">
904906
<input type="hidden" name="nav-menu-data">
905907
<?php
906908
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );

0 commit comments

Comments
 (0)