From 5cb54881e8fb33770d6c2e5d17aae871ea3c1316 Mon Sep 17 00:00:00 2001 From: Jake Spurlock Date: Mon, 15 Jun 2020 23:20:18 +0000 Subject: [PATCH] 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 --- src/wp-admin/css/nav-menus.css | 11 ---------- src/wp-admin/nav-menus.php | 40 ++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/wp-admin/css/nav-menus.css b/src/wp-admin/css/nav-menus.css index 8b68ac5400..83907c6240 100644 --- a/src/wp-admin/css/nav-menus.css +++ b/src/wp-admin/css/nav-menus.css @@ -65,13 +65,6 @@ ul.add-menu-item-tabs li { position: relative; } -.blank-slate .menu-settings { - border: none; - margin-top: 0; - padding-top: 0; - overflow: hidden; -} - .is-submenu { color: #555d66; /* #fafafa background */ font-style: italic; @@ -749,10 +742,6 @@ body.menu-max-depth-11 { min-width: 1280px !important; } float: right; } -.nav-menus-php .blank-slate .menu-settings { - display: none; -} - /* Same as the Publish Meta Box #delete-action */ .nav-menus-php .delete-action { float: left; diff --git a/src/wp-admin/nav-menus.php b/src/wp-admin/nav-menus.php index 70393b4a79..b9aee875f1 100644 --- a/src/wp-admin/nav-menus.php +++ b/src/wp-admin/nav-menus.php @@ -300,22 +300,12 @@ switch ( $action ) { case 'update': check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); - // 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 ) { - unset( $menu_locations[ $location ] ); - } - } - // Merge new and existing menu locations if any new ones are set. if ( isset( $_POST['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 ); - // Add Menu. if ( 0 == $nav_menu_selected_id ) { $new_menu_title = trim( esc_html( $_POST['menu-name'] ) ); @@ -332,9 +322,18 @@ switch ( $action ) { if ( isset( $_REQUEST['menu-item'] ) ) { wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) ); } - if ( isset( $_REQUEST['zero-menu-state'] ) ) { + // Set the menu_location value correctly for the newly created menu. + foreach ( $menu_locations as $location => $id ) { + if ( 0 === $id ) { + $menu_locations[ $location ] = $nav_menu_selected_id; + } + } + set_theme_mod( 'nav_menu_locations', $menu_locations ); + if ( isset( $_REQUEST['zero-menu-state'] ) || ! empty( $_POST['auto-add-pages'] ) ) { // If there are menu items, add them. wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ); + } + if ( isset( $_REQUEST['zero-menu-state'] ) ) { // Auto-save nav_menu_locations. $locations = get_nav_menu_locations(); foreach ( $locations as $location => $menu_id ) { @@ -359,8 +358,17 @@ switch ( $action ) { $messages[] = '

' . __( 'Please enter a valid menu name.' ) . '

'; } - // Update existing menu. + // Update existing menu. } else { + // 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 ) { + unset( $menu_locations[ $location ] ); + } + } + + // Set menu locations. + set_theme_mod( 'nav_menu_locations', $menu_locations ); $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id ); @@ -893,14 +901,8 @@ require_once ABSPATH . 'wp-admin/admin-header.php';