314 |
314 |
315 case 'update': |
315 case 'update': |
316 check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); |
316 check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); |
317 |
317 |
318 // Merge new and existing menu locations if any new ones are set. |
318 // Merge new and existing menu locations if any new ones are set. |
|
319 $new_menu_locations = array(); |
319 if ( isset( $_POST['menu-locations'] ) ) { |
320 if ( isset( $_POST['menu-locations'] ) ) { |
320 $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] ); |
321 $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] ); |
321 $menu_locations = array_merge( $menu_locations, $new_menu_locations ); |
322 $menu_locations = array_merge( $menu_locations, $new_menu_locations ); |
322 } |
323 } |
323 |
324 |
337 |
338 |
338 if ( isset( $_REQUEST['menu-item'] ) ) { |
339 if ( isset( $_REQUEST['menu-item'] ) ) { |
339 wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) ); |
340 wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) ); |
340 } |
341 } |
341 |
342 |
342 // Set the menu_location value correctly for the newly created menu. |
|
343 foreach ( $menu_locations as $location => $id ) { |
|
344 if ( 0 === $id ) { |
|
345 $menu_locations[ $location ] = $nav_menu_selected_id; |
|
346 } |
|
347 } |
|
348 |
|
349 set_theme_mod( 'nav_menu_locations', $menu_locations ); |
|
350 |
|
351 if ( isset( $_REQUEST['zero-menu-state'] ) || ! empty( $_POST['auto-add-pages'] ) ) { |
343 if ( isset( $_REQUEST['zero-menu-state'] ) || ! empty( $_POST['auto-add-pages'] ) ) { |
352 // If there are menu items, add them. |
344 // If there are menu items, add them. |
353 wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ); |
345 wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ); |
354 } |
346 } |
355 |
347 |
358 $locations = get_nav_menu_locations(); |
350 $locations = get_nav_menu_locations(); |
359 |
351 |
360 foreach ( $locations as $location => $menu_id ) { |
352 foreach ( $locations as $location => $menu_id ) { |
361 $locations[ $location ] = $nav_menu_selected_id; |
353 $locations[ $location ] = $nav_menu_selected_id; |
362 break; // There should only be 1. |
354 break; // There should only be 1. |
|
355 } |
|
356 |
|
357 set_theme_mod( 'nav_menu_locations', $locations ); |
|
358 } elseif ( count( $new_menu_locations ) > 0 ) { |
|
359 // If locations have been selected for the new menu, save those. |
|
360 $locations = get_nav_menu_locations(); |
|
361 |
|
362 foreach ( array_keys( $new_menu_locations ) as $location ) { |
|
363 $locations[ $location ] = $nav_menu_selected_id; |
363 } |
364 } |
364 |
365 |
365 set_theme_mod( 'nav_menu_locations', $locations ); |
366 set_theme_mod( 'nav_menu_locations', $locations ); |
366 } |
367 } |
367 |
368 |
422 if ( ! is_wp_error( $_menu_object ) ) { |
423 if ( ! is_wp_error( $_menu_object ) ) { |
423 $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) ); |
424 $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) ); |
424 |
425 |
425 // If the menu ID changed, redirect to the new URL. |
426 // If the menu ID changed, redirect to the new URL. |
426 if ( $nav_menu_selected_id !== $_nav_menu_selected_id ) { |
427 if ( $nav_menu_selected_id !== $_nav_menu_selected_id ) { |
427 wp_redirect( admin_url( 'nav-menus.php?menu=' . intval( $_nav_menu_selected_id ) ) ); |
428 wp_redirect( admin_url( 'nav-menus.php?menu=' . (int) $_nav_menu_selected_id ) ); |
428 exit; |
429 exit; |
429 } |
430 } |
430 } |
431 } |
431 } |
432 } |
432 |
433 |
492 'outFrom' => __( 'Out from under %s' ), |
493 'outFrom' => __( 'Out from under %s' ), |
493 /* translators: 1: Item name, 2: Item position, 3: Total number of items. */ |
494 /* translators: 1: Item name, 2: Item position, 3: Total number of items. */ |
494 'menuFocus' => __( '%1$s. Menu item %2$d of %3$d.' ), |
495 'menuFocus' => __( '%1$s. Menu item %2$d of %3$d.' ), |
495 /* translators: 1: Item name, 2: Item position, 3: Parent item name. */ |
496 /* translators: 1: Item name, 2: Item position, 3: Parent item name. */ |
496 'subMenuFocus' => __( '%1$s. Sub item number %2$d under %3$s.' ), |
497 'subMenuFocus' => __( '%1$s. Sub item number %2$d under %3$s.' ), |
|
498 /* translators: %s: Item name. */ |
|
499 'menuItemDeletion' => __( 'item %s' ), |
|
500 /* translators: %s: Item name. */ |
|
501 'itemsDeleted' => __( 'Deleted menu item: %s.' ), |
497 ); |
502 ); |
498 wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n ); |
503 wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n ); |
499 |
504 |
500 /* |
505 /* |
501 * Redirect to add screen if there are no menus and this users has either zero, |
506 * Redirect to add screen if there are no menus and this users has either zero, |
594 $overview = '<p>' . __( 'This screen is used for managing your navigation menus.' ) . '</p>'; |
599 $overview = '<p>' . __( 'This screen is used for managing your navigation menus.' ) . '</p>'; |
595 $overview .= '<p>' . sprintf( |
600 $overview .= '<p>' . sprintf( |
596 /* translators: 1: URL to Widgets screen, 2 and 3: The names of the default themes. */ |
601 /* translators: 1: URL to Widgets screen, 2 and 3: The names of the default themes. */ |
597 __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a “Navigation Menu” widget on the <a href="%1$s">Widgets</a> screen. If your theme does not support the navigation menus feature (the default themes, %2$s and %3$s, do), you can learn about adding this support by following the Documentation link to the side.' ), |
602 __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a “Navigation Menu” widget on the <a href="%1$s">Widgets</a> screen. If your theme does not support the navigation menus feature (the default themes, %2$s and %3$s, do), you can learn about adding this support by following the Documentation link to the side.' ), |
598 admin_url( 'widgets.php' ), |
603 admin_url( 'widgets.php' ), |
599 'Twenty Nineteen', |
604 'Twenty Twenty', |
600 'Twenty Twenty' |
605 'Twenty Twenty-One' |
601 ) . '</p>'; |
606 ) . '</p>'; |
602 $overview .= '<p>' . __( 'From this screen you can:' ) . '</p>'; |
607 $overview .= '<p>' . __( 'From this screen you can:' ) . '</p>'; |
603 $overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>'; |
608 $overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>'; |
604 $overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>'; |
609 $overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>'; |
605 |
610 |
661 |
666 |
662 // Get the admin header. |
667 // Get the admin header. |
663 require_once ABSPATH . 'wp-admin/admin-header.php'; |
668 require_once ABSPATH . 'wp-admin/admin-header.php'; |
664 ?> |
669 ?> |
665 <div class="wrap"> |
670 <div class="wrap"> |
666 <h1 class="wp-heading-inline"><?php echo esc_html( __( 'Menus' ) ); ?></h1> |
671 <h1 class="wp-heading-inline"><?php esc_html_e( 'Menus' ); ?></h1> |
667 <?php |
672 <?php |
668 if ( current_user_can( 'customize' ) ) : |
673 if ( current_user_can( 'customize' ) ) : |
669 $focus = $locations_screen ? array( 'section' => 'menu_locations' ) : array( 'panel' => 'nav_menus' ); |
674 $focus = $locations_screen ? array( 'section' => 'menu_locations' ) : array( 'panel' => 'nav_menus' ); |
670 printf( |
675 printf( |
671 ' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>', |
676 ' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>', |
692 ?> |
697 ?> |
693 |
698 |
694 <hr class="wp-header-end"> |
699 <hr class="wp-header-end"> |
695 |
700 |
696 <nav class="nav-tab-wrapper wp-clearfix" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>"> |
701 <nav class="nav-tab-wrapper wp-clearfix" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>"> |
697 <a href="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-tab<?php echo $nav_tab_active_class; ?>"<?php echo $nav_aria_current; ?>><?php esc_html_e( 'Edit Menus' ); ?></a> |
702 <a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>" class="nav-tab<?php echo $nav_tab_active_class; ?>"<?php echo $nav_aria_current; ?>><?php esc_html_e( 'Edit Menus' ); ?></a> |
698 <?php |
703 <?php |
699 if ( $num_locations && $menu_count ) { |
704 if ( $num_locations && $menu_count ) { |
700 $active_tab_class = ''; |
705 $active_tab_class = ''; |
701 $aria_current = ''; |
706 $aria_current = ''; |
702 |
707 |
843 ); |
848 ); |
844 ?> |
849 ?> |
845 <span class="screen-reader-text"><?php _e( 'Click the Save Menu button to save your changes.' ); ?></span> |
850 <span class="screen-reader-text"><?php _e( 'Click the Save Menu button to save your changes.' ); ?></span> |
846 </span><!-- /add-edit-menu-action --> |
851 </span><!-- /add-edit-menu-action --> |
847 <?php else : ?> |
852 <?php else : ?> |
848 <form method="get" action="<?php echo admin_url( 'nav-menus.php' ); ?>"> |
853 <form method="get" action="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"> |
849 <input type="hidden" name="action" value="edit" /> |
854 <input type="hidden" name="action" value="edit" /> |
850 <label for="select-menu-to-edit" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label> |
855 <label for="select-menu-to-edit" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label> |
851 <select name="menu" id="select-menu-to-edit"> |
856 <select name="menu" id="select-menu-to-edit"> |
852 <?php if ( $add_new_screen ) : ?> |
857 <?php if ( $add_new_screen ) : ?> |
853 <option value="0" selected="selected"><?php _e( '— Select —' ); ?></option> |
858 <option value="0" selected="selected"><?php _e( '— Select —' ); ?></option> |
959 <input type="hidden" name="action" value="update" /> |
964 <input type="hidden" name="action" value="update" /> |
960 <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> |
965 <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> |
961 <div id="nav-menu-header"> |
966 <div id="nav-menu-header"> |
962 <div class="major-publishing-actions wp-clearfix"> |
967 <div class="major-publishing-actions wp-clearfix"> |
963 <label class="menu-name-label" for="menu-name"><?php _e( 'Menu Name' ); ?></label> |
968 <label class="menu-name-label" for="menu-name"><?php _e( 'Menu Name' ); ?></label> |
964 <input name="menu-name" id="menu-name" type="text" class="menu-name regular-text menu-item-textbox" <?php echo $menu_name_val . $menu_name_aria_desc; ?> /> |
969 <input name="menu-name" id="menu-name" type="text" class="menu-name regular-text menu-item-textbox form-required" required="required" <?php echo $menu_name_val . $menu_name_aria_desc; ?> /> |
965 <div class="publishing-action"> |
970 <div class="publishing-action"> |
966 <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?> |
971 <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?> |
967 </div><!-- END .publishing-action --> |
972 </div><!-- END .publishing-action --> |
968 </div><!-- END .major-publishing-actions --> |
973 </div><!-- END .major-publishing-actions --> |
969 </div><!-- END .nav-menu-header --> |
974 </div><!-- END .nav-menu-header --> |
970 <div id="post-body"> |
975 <div id="post-body"> |
971 <div id="post-body-content" class="wp-clearfix"> |
976 <div id="post-body-content" class="wp-clearfix"> |
972 <?php if ( ! $add_new_screen ) : ?> |
977 <?php if ( ! $add_new_screen ) : ?> |
973 |
|
974 <?php |
978 <?php |
975 $hide_style = ''; |
979 $hide_style = ''; |
976 |
980 |
977 if ( isset( $menu_items ) && 0 === count( $menu_items ) ) { |
981 if ( isset( $menu_items ) && 0 === count( $menu_items ) ) { |
978 $hide_style = 'style="display: none;"'; |
982 $hide_style = 'style="display: none;"'; |
986 ?> |
990 ?> |
987 <div class="drag-instructions post-body-plain" <?php echo $hide_style; ?>> |
991 <div class="drag-instructions post-body-plain" <?php echo $hide_style; ?>> |
988 <p><?php echo $starter_copy; ?></p> |
992 <p><?php echo $starter_copy; ?></p> |
989 </div> |
993 </div> |
990 |
994 |
|
995 <?php if ( ! $add_new_screen ) : ?> |
|
996 <div id="nav-menu-bulk-actions-top" class="bulk-actions"> |
|
997 <label class="bulk-select-button" for="bulk-select-switcher-top"> |
|
998 <input type="checkbox" id="bulk-select-switcher-top" name="bulk-select-switcher-top" class="bulk-select-switcher"> |
|
999 <span class="bulk-select-button-label"><?php _e( 'Bulk Select' ); ?></span> |
|
1000 </label> |
|
1001 </div> |
|
1002 <?php endif; ?> |
|
1003 |
991 <?php |
1004 <?php |
992 if ( isset( $edit_markup ) && ! is_wp_error( $edit_markup ) ) { |
1005 if ( isset( $edit_markup ) && ! is_wp_error( $edit_markup ) ) { |
993 echo $edit_markup; |
1006 echo $edit_markup; |
994 } else { |
1007 } else { |
995 ?> |
1008 ?> |
1011 |
1024 |
1012 if ( $one_theme_location_no_menus ) { |
1025 if ( $one_theme_location_no_menus ) { |
1013 $no_menus_style = 'style="display: none;"'; |
1026 $no_menus_style = 'style="display: none;"'; |
1014 } |
1027 } |
1015 ?> |
1028 ?> |
|
1029 |
|
1030 <?php if ( ! $add_new_screen ) : ?> |
|
1031 <div id="nav-menu-bulk-actions-bottom" class="bulk-actions"> |
|
1032 <label class="bulk-select-button" for="bulk-select-switcher-bottom"> |
|
1033 <input type="checkbox" id="bulk-select-switcher-bottom" name="bulk-select-switcher-top" class="bulk-select-switcher"> |
|
1034 <span class="bulk-select-button-label"><?php _e( 'Bulk Select' ); ?></span> |
|
1035 </label> |
|
1036 <input type="button" class="deletion menu-items-delete disabled" value="<?php _e( 'Remove Selected Items' ); ?>"> |
|
1037 <div id="pending-menu-items-to-delete"> |
|
1038 <p><?php _e( 'List of menu items selected for deletion:' ); ?></p> |
|
1039 <ul></ul> |
|
1040 </div> |
|
1041 </div> |
|
1042 <?php endif; ?> |
|
1043 |
1016 <div class="menu-settings" <?php echo $no_menus_style; ?>> |
1044 <div class="menu-settings" <?php echo $no_menus_style; ?>> |
1017 <h3><?php _e( 'Menu Settings' ); ?></h3> |
1045 <h3><?php _e( 'Menu Settings' ); ?></h3> |
1018 <?php |
1046 <?php |
1019 if ( ! isset( $auto_add ) ) { |
1047 if ( ! isset( $auto_add ) ) { |
1020 $auto_add = get_option( 'nav_menu_options' ); |
1048 $auto_add = get_option( 'nav_menu_options' ); |
1040 |
1068 |
1041 <fieldset class="menu-settings-group menu-theme-locations"> |
1069 <fieldset class="menu-settings-group menu-theme-locations"> |
1042 <legend class="menu-settings-group-name howto"><?php _e( 'Display location' ); ?></legend> |
1070 <legend class="menu-settings-group-name howto"><?php _e( 'Display location' ); ?></legend> |
1043 <?php |
1071 <?php |
1044 foreach ( $locations as $location => $description ) : |
1072 foreach ( $locations as $location => $description ) : |
1045 $checked = isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] === $nav_menu_selected_id; |
1073 $checked = false; |
|
1074 |
|
1075 if ( isset( $menu_locations[ $location ] ) |
|
1076 && 0 !== $nav_menu_selected_id |
|
1077 && $menu_locations[ $location ] === $nav_menu_selected_id |
|
1078 ) { |
|
1079 $checked = true; |
|
1080 } |
1046 ?> |
1081 ?> |
1047 <div class="menu-settings-input checkbox-input"> |
1082 <div class="menu-settings-input checkbox-input"> |
1048 <input type="checkbox"<?php checked( $checked ); ?> name="menu-locations[<?php echo esc_attr( $location ); ?>]" id="locations-<?php echo esc_attr( $location ); ?>" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> |
1083 <input type="checkbox"<?php checked( $checked ); ?> name="menu-locations[<?php echo esc_attr( $location ); ?>]" id="locations-<?php echo esc_attr( $location ); ?>" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> |
1049 <label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label> |
1084 <label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label> |
1050 <?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] !== $nav_menu_selected_id ) : ?> |
1085 <?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] !== $nav_menu_selected_id ) : ?> |