|
300 | 300 | case 'update': |
301 | 301 | check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); |
302 | 302 |
|
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 | | - |
310 | 303 | // Merge new and existing menu locations if any new ones are set. |
311 | 304 | if ( isset( $_POST['menu-locations'] ) ) { |
312 | 305 | $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] ); |
313 | 306 | $menu_locations = array_merge( $menu_locations, $new_menu_locations ); |
314 | 307 | } |
315 | 308 |
|
316 | | - // Set menu locations. |
317 | | - set_theme_mod( 'nav_menu_locations', $menu_locations ); |
318 | | - |
319 | 309 | // Add Menu. |
320 | 310 | if ( 0 == $nav_menu_selected_id ) { |
321 | 311 | $new_menu_title = trim( esc_html( $_POST['menu-name'] ) ); |
|
332 | 322 | if ( isset( $_REQUEST['menu-item'] ) ) { |
333 | 323 | wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) ); |
334 | 324 | } |
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'] ) ) { |
336 | 333 | // If there are menu items, add them. |
337 | 334 | wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ); |
| 335 | + } |
| 336 | + if ( isset( $_REQUEST['zero-menu-state'] ) ) { |
338 | 337 | // Auto-save nav_menu_locations. |
339 | 338 | $locations = get_nav_menu_locations(); |
340 | 339 | foreach ( $locations as $location => $menu_id ) { |
|
359 | 358 | $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>'; |
360 | 359 | } |
361 | 360 |
|
362 | | - // Update existing menu. |
| 361 | + // Update existing menu. |
363 | 362 | } 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 ); |
364 | 372 |
|
365 | 373 | $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id ); |
366 | 374 |
|
@@ -893,14 +901,8 @@ function wp_nav_menu_max_depth( $classes ) { |
893 | 901 | <div id="menu-management-liquid"> |
894 | 902 | <div id="menu-management"> |
895 | 903 | <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 | | - ?> |
902 | 904 | <h2><?php _e( 'Menu structure' ); ?></h2> |
903 | | - <div class="menu-edit <?php echo $new_screen_class; ?>"> |
| 905 | + <div class="menu-edit"> |
904 | 906 | <input type="hidden" name="nav-menu-data"> |
905 | 907 | <?php |
906 | 908 | wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
|
0 commit comments