wp/wp-admin/nav-menus.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     8  * @package WordPress
     8  * @package WordPress
     9  * @subpackage Administration
     9  * @subpackage Administration
    10  */
    10  */
    11 
    11 
    12 /** Load WordPress Administration Bootstrap */
    12 /** Load WordPress Administration Bootstrap */
    13 require_once( dirname( __FILE__ ) . '/admin.php' );
    13 require_once __DIR__ . '/admin.php';
    14 
    14 
    15 // Load all the nav menu interface functions
    15 // Load all the nav menu interface functions.
    16 require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
    16 require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
    17 
    17 
    18 if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) ) {
    18 if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) ) {
    19 	wp_die( __( 'Your theme does not support navigation menus or widgets.' ) );
    19 	wp_die( __( 'Your theme does not support navigation menus or widgets.' ) );
    20 }
    20 }
    21 
    21 
    22 // Permissions Check
    22 // Permissions check.
    23 if ( ! current_user_can( 'edit_theme_options' ) ) {
    23 if ( ! current_user_can( 'edit_theme_options' ) ) {
    24 	wp_die(
    24 	wp_die(
    25 		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
    25 		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
    26 		'<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
    26 		'<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
    27 		403
    27 		403
    32 
    32 
    33 if ( wp_is_mobile() ) {
    33 if ( wp_is_mobile() ) {
    34 	wp_enqueue_script( 'jquery-touch-punch' );
    34 	wp_enqueue_script( 'jquery-touch-punch' );
    35 }
    35 }
    36 
    36 
    37 // Container for any messages displayed to the user
    37 // Container for any messages displayed to the user.
    38 $messages = array();
    38 $messages = array();
    39 
    39 
    40 // Container that stores the name of the active menu
    40 // Container that stores the name of the active menu.
    41 $nav_menu_selected_title = '';
    41 $nav_menu_selected_title = '';
    42 
    42 
    43 // The menu id of the current menu being edited
    43 // The menu id of the current menu being edited.
    44 $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
    44 $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
    45 
    45 
    46 // Get existing menu locations assignments
    46 // Get existing menu locations assignments.
    47 $locations      = get_registered_nav_menus();
    47 $locations      = get_registered_nav_menus();
    48 $menu_locations = get_nav_menu_locations();
    48 $menu_locations = get_nav_menu_locations();
    49 $num_locations  = count( array_keys( $locations ) );
    49 $num_locations  = count( array_keys( $locations ) );
    50 
    50 
    51 // Allowed actions: add, update, delete
    51 // Allowed actions: add, update, delete.
    52 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
    52 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
    53 
    53 
    54 /*
    54 /*
    55  * If a JSON blob of navigation menu data is found, expand it and inject it
    55  * If a JSON blob of navigation menu data is found, expand it and inject it
    56  * into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134.
    56  * into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134.
    58 _wp_expand_nav_menu_post_data();
    58 _wp_expand_nav_menu_post_data();
    59 
    59 
    60 switch ( $action ) {
    60 switch ( $action ) {
    61 	case 'add-menu-item':
    61 	case 'add-menu-item':
    62 		check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
    62 		check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
       
    63 
    63 		if ( isset( $_REQUEST['nav-menu-locations'] ) ) {
    64 		if ( isset( $_REQUEST['nav-menu-locations'] ) ) {
    64 			set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) );
    65 			set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) );
    65 		} elseif ( isset( $_REQUEST['menu-item'] ) ) {
    66 		} elseif ( isset( $_REQUEST['menu-item'] ) ) {
    66 			wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] );
    67 			wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] );
    67 		}
    68 		}
       
    69 
    68 		break;
    70 		break;
       
    71 
    69 	case 'move-down-menu-item':
    72 	case 'move-down-menu-item':
    70 		// Moving down a menu item is the same as moving up the next in order.
    73 		// Moving down a menu item is the same as moving up the next in order.
    71 		check_admin_referer( 'move-menu_item' );
    74 		check_admin_referer( 'move-menu_item' );
       
    75 
    72 		$menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
    76 		$menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
       
    77 
    73 		if ( is_nav_menu_item( $menu_item_id ) ) {
    78 		if ( is_nav_menu_item( $menu_item_id ) ) {
    74 			$menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
    79 			$menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
       
    80 
    75 			if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
    81 			if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
    76 				$menu_id            = (int) $menus[0];
    82 				$menu_id            = (int) $menus[0];
    77 				$ordered_menu_items = wp_get_nav_menu_items( $menu_id );
    83 				$ordered_menu_items = wp_get_nav_menu_items( $menu_id );
    78 				$menu_item_data     = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
    84 				$menu_item_data     = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
    79 
    85 
    80 				// Set up the data we need in one pass through the array of menu items.
    86 				// Set up the data we need in one pass through the array of menu items.
    81 				$dbids_to_orders = array();
    87 				$dbids_to_orders = array();
    82 				$orders_to_dbids = array();
    88 				$orders_to_dbids = array();
       
    89 
    83 				foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
    90 				foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
    84 					if ( isset( $ordered_menu_item_object->ID ) ) {
    91 					if ( isset( $ordered_menu_item_object->ID ) ) {
    85 						if ( isset( $ordered_menu_item_object->menu_order ) ) {
    92 						if ( isset( $ordered_menu_item_object->menu_order ) ) {
    86 							$dbids_to_orders[ $ordered_menu_item_object->ID ]         = $ordered_menu_item_object->menu_order;
    93 							$dbids_to_orders[ $ordered_menu_item_object->ID ]         = $ordered_menu_item_object->menu_order;
    87 							$orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID;
    94 							$orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID;
    88 						}
    95 						}
    89 					}
    96 					}
    90 				}
    97 				}
    91 
    98 
    92 				// Get next in order.
    99 				// Get next in order.
    93 				if (
   100 				if ( isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] + 1 ] ) ) {
    94 					isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] + 1 ] )
       
    95 				) {
       
    96 					$next_item_id   = $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] + 1 ];
   101 					$next_item_id   = $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] + 1 ];
    97 					$next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) );
   102 					$next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) );
    98 
   103 
    99 					// If not siblings of same parent, bubble menu item up but keep order.
   104 					// If not siblings of same parent, bubble menu item up but keep order.
   100 					if (
   105 					if ( ! empty( $menu_item_data['menu_item_parent'] )
   101 						! empty( $menu_item_data['menu_item_parent'] ) &&
   106 						&& ( empty( $next_item_data['menu_item_parent'] )
   102 						(
   107 							|| (int) $next_item_data['menu_item_parent'] !== (int) $menu_item_data['menu_item_parent'] )
   103 							empty( $next_item_data['menu_item_parent'] ) ||
       
   104 							$next_item_data['menu_item_parent'] != $menu_item_data['menu_item_parent']
       
   105 						)
       
   106 					) {
   108 					) {
   107 
   109 						if ( in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true ) ) {
   108 						$parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
   110 							$parent_db_id = (int) $menu_item_data['menu_item_parent'];
       
   111 						} else {
       
   112 							$parent_db_id = 0;
       
   113 						}
   109 
   114 
   110 						$parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
   115 						$parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
   111 
   116 
   112 						if ( ! is_wp_error( $parent_object ) ) {
   117 						if ( ! is_wp_error( $parent_object ) ) {
   113 							$parent_data                        = (array) $parent_object;
   118 							$parent_data                        = (array) $parent_object;
   114 							$menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
   119 							$menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
   115 							update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
   120 							update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
   116 
       
   117 						}
   121 						}
   118 
   122 
   119 						// Make menu item a child of its next sibling.
   123 						// Make menu item a child of its next sibling.
   120 					} else {
   124 					} else {
   121 						$next_item_data['menu_order'] = $next_item_data['menu_order'] - 1;
   125 						$next_item_data['menu_order'] = $next_item_data['menu_order'] - 1;
   127 						wp_update_post( $menu_item_data );
   131 						wp_update_post( $menu_item_data );
   128 						wp_update_post( $next_item_data );
   132 						wp_update_post( $next_item_data );
   129 					}
   133 					}
   130 
   134 
   131 					// The item is last but still has a parent, so bubble up.
   135 					// The item is last but still has a parent, so bubble up.
   132 				} elseif (
   136 				} elseif ( ! empty( $menu_item_data['menu_item_parent'] )
   133 					! empty( $menu_item_data['menu_item_parent'] ) &&
   137 					&& in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true )
   134 					in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids )
       
   135 				) {
   138 				) {
   136 					$menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true );
   139 					$menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true );
   137 					update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
   140 					update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
   138 				}
   141 				}
   139 			}
   142 			}
   140 		}
   143 		}
   141 
   144 
   142 		break;
   145 		break;
       
   146 
   143 	case 'move-up-menu-item':
   147 	case 'move-up-menu-item':
   144 		check_admin_referer( 'move-menu_item' );
   148 		check_admin_referer( 'move-menu_item' );
       
   149 
   145 		$menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
   150 		$menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
       
   151 
   146 		if ( is_nav_menu_item( $menu_item_id ) ) {
   152 		if ( is_nav_menu_item( $menu_item_id ) ) {
   147 			$menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
   153 			if ( isset( $_REQUEST['menu'] ) ) {
       
   154 				$menus = array( (int) $_REQUEST['menu'] );
       
   155 			} else {
       
   156 				$menus = wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
       
   157 			}
       
   158 
   148 			if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
   159 			if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
   149 				$menu_id            = (int) $menus[0];
   160 				$menu_id            = (int) $menus[0];
   150 				$ordered_menu_items = wp_get_nav_menu_items( $menu_id );
   161 				$ordered_menu_items = wp_get_nav_menu_items( $menu_id );
   151 				$menu_item_data     = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
   162 				$menu_item_data     = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
   152 
   163 
   153 				// Set up the data we need in one pass through the array of menu items.
   164 				// Set up the data we need in one pass through the array of menu items.
   154 				$dbids_to_orders = array();
   165 				$dbids_to_orders = array();
   155 				$orders_to_dbids = array();
   166 				$orders_to_dbids = array();
       
   167 
   156 				foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
   168 				foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
   157 					if ( isset( $ordered_menu_item_object->ID ) ) {
   169 					if ( isset( $ordered_menu_item_object->ID ) ) {
   158 						if ( isset( $ordered_menu_item_object->menu_order ) ) {
   170 						if ( isset( $ordered_menu_item_object->menu_order ) ) {
   159 							$dbids_to_orders[ $ordered_menu_item_object->ID ]         = $ordered_menu_item_object->menu_order;
   171 							$dbids_to_orders[ $ordered_menu_item_object->ID ]         = $ordered_menu_item_object->menu_order;
   160 							$orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID;
   172 							$orders_to_dbids[ $ordered_menu_item_object->menu_order ] = $ordered_menu_item_object->ID;
   161 						}
   173 						}
   162 					}
   174 					}
   163 				}
   175 				}
   164 
   176 
   165 				// If this menu item is not first.
   177 				// If this menu item is not first.
   166 				if ( ! empty( $dbids_to_orders[ $menu_item_id ] ) && ! empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) ) {
   178 				if ( ! empty( $dbids_to_orders[ $menu_item_id ] )
       
   179 					&& ! empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
       
   180 				) {
   167 
   181 
   168 					// If this menu item is a child of the previous.
   182 					// If this menu item is a child of the previous.
   169 					if (
   183 					if ( ! empty( $menu_item_data['menu_item_parent'] )
   170 						! empty( $menu_item_data['menu_item_parent'] ) &&
   184 						&& in_array( (int) $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ), true )
   171 						in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) &&
   185 						&& isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
   172 						isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) &&
   186 						&& ( (int) $menu_item_data['menu_item_parent'] === $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
   173 						( $menu_item_data['menu_item_parent'] == $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
       
   174 					) {
   187 					) {
   175 						$parent_db_id  = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
   188 						if ( in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true ) ) {
       
   189 							$parent_db_id = (int) $menu_item_data['menu_item_parent'];
       
   190 						} else {
       
   191 							$parent_db_id = 0;
       
   192 						}
       
   193 
   176 						$parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
   194 						$parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
   177 
   195 
   178 						if ( ! is_wp_error( $parent_object ) ) {
   196 						if ( ! is_wp_error( $parent_object ) ) {
   179 							$parent_data = (array) $parent_object;
   197 							$parent_data = (array) $parent_object;
   180 
   198 
   181 							/*
   199 							/*
   182 							 * If there is something before the parent and parent a child of it,
   200 							 * If there is something before the parent and parent a child of it,
   183 							 * make menu item a child also of it.
   201 							 * make menu item a child also of it.
   184 							 */
   202 							 */
   185 							if (
   203 							if ( ! empty( $dbids_to_orders[ $parent_db_id ] )
   186 								! empty( $dbids_to_orders[ $parent_db_id ] ) &&
   204 								&& ! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] )
   187 								! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] ) &&
   205 								&& ! empty( $parent_data['menu_item_parent'] )
   188 								! empty( $parent_data['menu_item_parent'] )
       
   189 							) {
   206 							) {
   190 								$menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
   207 								$menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
   191 
   208 
   192 								/*
   209 								/*
   193 								* Else if there is something before parent and parent not a child of it,
   210 								* Else if there is something before parent and parent not a child of it,
   194 								* make menu item a child of that something's parent
   211 								* make menu item a child of that something's parent
   195 								*/
   212 								*/
   196 							} elseif (
   213 							} elseif ( ! empty( $dbids_to_orders[ $parent_db_id ] )
   197 								! empty( $dbids_to_orders[ $parent_db_id ] ) &&
   214 								&& ! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] )
   198 								! empty( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ] )
       
   199 							) {
   215 							) {
   200 								$_possible_parent_id = (int) get_post_meta( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ], '_menu_item_menu_item_parent', true );
   216 								$_possible_parent_id = (int) get_post_meta( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ], '_menu_item_menu_item_parent', true );
   201 								if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ) ) ) {
   217 
       
   218 								if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ), true ) ) {
   202 									$menu_item_data['menu_item_parent'] = $_possible_parent_id;
   219 									$menu_item_data['menu_item_parent'] = $_possible_parent_id;
   203 								} else {
   220 								} else {
   204 									$menu_item_data['menu_item_parent'] = 0;
   221 									$menu_item_data['menu_item_parent'] = 0;
   205 								}
   222 								}
   206 
   223 
   220 							wp_update_post( $menu_item_data );
   237 							wp_update_post( $menu_item_data );
   221 							wp_update_post( $parent_data );
   238 							wp_update_post( $parent_data );
   222 						}
   239 						}
   223 
   240 
   224 						// Else this menu item is not a child of the previous.
   241 						// Else this menu item is not a child of the previous.
   225 					} elseif (
   242 					} elseif ( empty( $menu_item_data['menu_order'] )
   226 						empty( $menu_item_data['menu_order'] ) ||
   243 						|| empty( $menu_item_data['menu_item_parent'] )
   227 						empty( $menu_item_data['menu_item_parent'] ) ||
   244 						|| ! in_array( (int) $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ), true )
   228 						! in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) ||
   245 						|| empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
   229 						empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) ||
   246 						|| $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] !== (int) $menu_item_data['menu_item_parent']
   230 						$orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] != $menu_item_data['menu_item_parent']
       
   231 					) {
   247 					) {
   232 						// Just make it a child of the previous; keep the order.
   248 						// Just make it a child of the previous; keep the order.
   233 						$menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ];
   249 						$menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ];
   234 						update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
   250 						update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
   235 						wp_update_post( $menu_item_data );
   251 						wp_update_post( $menu_item_data );
   236 					}
   252 					}
   237 				}
   253 				}
   238 			}
   254 			}
   239 		}
   255 		}
       
   256 
   240 		break;
   257 		break;
   241 
   258 
   242 	case 'delete-menu-item':
   259 	case 'delete-menu-item':
   243 		$menu_item_id = (int) $_REQUEST['menu-item'];
   260 		$menu_item_id = (int) $_REQUEST['menu-item'];
   244 
   261 
   245 		check_admin_referer( 'delete-menu_item_' . $menu_item_id );
   262 		check_admin_referer( 'delete-menu_item_' . $menu_item_id );
   246 
   263 
   247 		if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) {
   264 		if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) {
   248 			$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'The menu item has been successfully deleted.' ) . '</p></div>';
   265 			$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'The menu item has been successfully deleted.' ) . '</p></div>';
   249 		}
   266 		}
       
   267 
   250 		break;
   268 		break;
   251 
   269 
   252 	case 'delete':
   270 	case 'delete':
   253 		check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
   271 		check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
       
   272 
   254 		if ( is_nav_menu( $nav_menu_selected_id ) ) {
   273 		if ( is_nav_menu( $nav_menu_selected_id ) ) {
   255 			$deletion = wp_delete_nav_menu( $nav_menu_selected_id );
   274 			$deletion = wp_delete_nav_menu( $nav_menu_selected_id );
   256 		} else {
   275 		} else {
   257 			// Reset the selected menu.
   276 			// Reset the selected menu.
   258 			$nav_menu_selected_id = 0;
   277 			$nav_menu_selected_id = 0;
   266 		if ( is_wp_error( $deletion ) ) {
   285 		if ( is_wp_error( $deletion ) ) {
   267 			$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>';
   286 			$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>';
   268 		} else {
   287 		} else {
   269 			$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'The menu has been successfully deleted.' ) . '</p></div>';
   288 			$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'The menu has been successfully deleted.' ) . '</p></div>';
   270 		}
   289 		}
       
   290 
   271 		break;
   291 		break;
   272 
   292 
   273 	case 'delete_menus':
   293 	case 'delete_menus':
   274 		check_admin_referer( 'nav_menus_bulk_actions' );
   294 		check_admin_referer( 'nav_menus_bulk_actions' );
       
   295 
   275 		foreach ( $_REQUEST['delete_menus'] as $menu_id_to_delete ) {
   296 		foreach ( $_REQUEST['delete_menus'] as $menu_id_to_delete ) {
   276 			if ( ! is_nav_menu( $menu_id_to_delete ) ) {
   297 			if ( ! is_nav_menu( $menu_id_to_delete ) ) {
   277 				continue;
   298 				continue;
   278 			}
   299 			}
   279 
   300 
   280 			$deletion = wp_delete_nav_menu( $menu_id_to_delete );
   301 			$deletion = wp_delete_nav_menu( $menu_id_to_delete );
       
   302 
   281 			if ( is_wp_error( $deletion ) ) {
   303 			if ( is_wp_error( $deletion ) ) {
   282 				$messages[]     = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>';
   304 				$messages[]     = '<div id="message" class="error notice is-dismissible"><p>' . $deletion->get_error_message() . '</p></div>';
   283 				$deletion_error = true;
   305 				$deletion_error = true;
   284 			}
   306 			}
   285 		}
   307 		}
   286 
   308 
   287 		if ( empty( $deletion_error ) ) {
   309 		if ( empty( $deletion_error ) ) {
   288 			$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Selected menus have been successfully deleted.' ) . '</p></div>';
   310 			$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Selected menus have been successfully deleted.' ) . '</p></div>';
   289 		}
   311 		}
       
   312 
   290 		break;
   313 		break;
   291 
   314 
   292 	case 'update':
   315 	case 'update':
   293 		check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
   316 		check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
   294 
       
   295 		// Remove menu locations that have been unchecked.
       
   296 		foreach ( $locations as $location => $description ) {
       
   297 			if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) ) && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id ) {
       
   298 				unset( $menu_locations[ $location ] );
       
   299 			}
       
   300 		}
       
   301 
   317 
   302 		// 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.
   303 		if ( isset( $_POST['menu-locations'] ) ) {
   319 		if ( isset( $_POST['menu-locations'] ) ) {
   304 			$new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
   320 			$new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
   305 			$menu_locations     = array_merge( $menu_locations, $new_menu_locations );
   321 			$menu_locations     = array_merge( $menu_locations, $new_menu_locations );
   306 		}
   322 		}
   307 
   323 
   308 		// Set menu locations.
       
   309 		set_theme_mod( 'nav_menu_locations', $menu_locations );
       
   310 
       
   311 		// Add Menu.
   324 		// Add Menu.
   312 		if ( 0 == $nav_menu_selected_id ) {
   325 		if ( 0 === $nav_menu_selected_id ) {
   313 			$new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
   326 			$new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
   314 
   327 
   315 			if ( $new_menu_title ) {
   328 			if ( $new_menu_title ) {
   316 				$_nav_menu_selected_id = wp_update_nav_menu_object( 0, array( 'menu-name' => $new_menu_title ) );
   329 				$_nav_menu_selected_id = wp_update_nav_menu_object( 0, array( 'menu-name' => $new_menu_title ) );
   317 
   330 
   319 					$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
   332 					$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
   320 				} else {
   333 				} else {
   321 					$_menu_object            = wp_get_nav_menu_object( $_nav_menu_selected_id );
   334 					$_menu_object            = wp_get_nav_menu_object( $_nav_menu_selected_id );
   322 					$nav_menu_selected_id    = $_nav_menu_selected_id;
   335 					$nav_menu_selected_id    = $_nav_menu_selected_id;
   323 					$nav_menu_selected_title = $_menu_object->name;
   336 					$nav_menu_selected_title = $_menu_object->name;
       
   337 
   324 					if ( isset( $_REQUEST['menu-item'] ) ) {
   338 					if ( isset( $_REQUEST['menu-item'] ) ) {
   325 						wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) );
   339 						wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) );
   326 					}
   340 					}
       
   341 
       
   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'] ) ) {
       
   352 						// If there are menu items, add them.
       
   353 						wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title );
       
   354 					}
       
   355 
   327 					if ( isset( $_REQUEST['zero-menu-state'] ) ) {
   356 					if ( isset( $_REQUEST['zero-menu-state'] ) ) {
   328 						// If there are menu items, add them
   357 						// Auto-save nav_menu_locations.
   329 						wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title );
       
   330 						// Auto-save nav_menu_locations
       
   331 						$locations = get_nav_menu_locations();
   358 						$locations = get_nav_menu_locations();
       
   359 
   332 						foreach ( $locations as $location => $menu_id ) {
   360 						foreach ( $locations as $location => $menu_id ) {
   333 								$locations[ $location ] = $nav_menu_selected_id;
   361 								$locations[ $location ] = $nav_menu_selected_id;
   334 								break; // There should only be 1
   362 								break; // There should only be 1.
   335 						}
   363 						}
       
   364 
   336 						set_theme_mod( 'nav_menu_locations', $locations );
   365 						set_theme_mod( 'nav_menu_locations', $locations );
   337 					}
   366 					}
       
   367 
   338 					if ( isset( $_REQUEST['use-location'] ) ) {
   368 					if ( isset( $_REQUEST['use-location'] ) ) {
   339 						$locations      = get_registered_nav_menus();
   369 						$locations      = get_registered_nav_menus();
   340 						$menu_locations = get_nav_menu_locations();
   370 						$menu_locations = get_nav_menu_locations();
       
   371 
   341 						if ( isset( $locations[ $_REQUEST['use-location'] ] ) ) {
   372 						if ( isset( $locations[ $_REQUEST['use-location'] ] ) ) {
   342 							$menu_locations[ $_REQUEST['use-location'] ] = $nav_menu_selected_id;
   373 							$menu_locations[ $_REQUEST['use-location'] ] = $nav_menu_selected_id;
   343 						}
   374 						}
       
   375 
   344 						set_theme_mod( 'nav_menu_locations', $menu_locations );
   376 						set_theme_mod( 'nav_menu_locations', $menu_locations );
   345 					}
   377 					}
   346 
   378 
   347 					// $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%s</strong> has been created.' ), $nav_menu_selected_title ) . '</p></div>';
       
   348 					wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) );
   379 					wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) );
   349 					exit();
   380 					exit;
   350 				}
   381 				}
   351 			} else {
   382 			} else {
   352 				$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
   383 				$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
   353 			}
   384 			}
   354 
   385 
   355 			// Update existing menu.
   386 			// Update existing menu.
   356 		} else {
   387 		} else {
       
   388 			// Remove menu locations that have been unchecked.
       
   389 			foreach ( $locations as $location => $description ) {
       
   390 				if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) )
       
   391 					&& isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] === $nav_menu_selected_id
       
   392 				) {
       
   393 					unset( $menu_locations[ $location ] );
       
   394 				}
       
   395 			}
       
   396 
       
   397 			// Set menu locations.
       
   398 			set_theme_mod( 'nav_menu_locations', $menu_locations );
   357 
   399 
   358 			$_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
   400 			$_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
   359 
   401 
   360 			$menu_title = trim( esc_html( $_POST['menu-name'] ) );
   402 			$menu_title = trim( esc_html( $_POST['menu-name'] ) );
       
   403 
   361 			if ( ! $menu_title ) {
   404 			if ( ! $menu_title ) {
   362 				$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
   405 				$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
   363 				$menu_title = $_menu_object->name;
   406 				$menu_title = $_menu_object->name;
   364 			}
   407 			}
   365 
   408 
   366 			if ( ! is_wp_error( $_menu_object ) ) {
   409 			if ( ! is_wp_error( $_menu_object ) ) {
   367 				$_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) );
   410 				$_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) );
       
   411 
   368 				if ( is_wp_error( $_nav_menu_selected_id ) ) {
   412 				if ( is_wp_error( $_nav_menu_selected_id ) ) {
   369 					$_menu_object = $_nav_menu_selected_id;
   413 					$_menu_object = $_nav_menu_selected_id;
   370 					$messages[]   = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
   414 					$messages[]   = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
   371 				} else {
   415 				} else {
   372 					$_menu_object            = wp_get_nav_menu_object( $_nav_menu_selected_id );
   416 					$_menu_object            = wp_get_nav_menu_object( $_nav_menu_selected_id );
   377 			// Update menu items.
   421 			// Update menu items.
   378 			if ( ! is_wp_error( $_menu_object ) ) {
   422 			if ( ! is_wp_error( $_menu_object ) ) {
   379 				$messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) );
   423 				$messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) );
   380 
   424 
   381 				// If the menu ID changed, redirect to the new URL.
   425 				// If the menu ID changed, redirect to the new URL.
   382 				if ( $nav_menu_selected_id != $_nav_menu_selected_id ) {
   426 				if ( $nav_menu_selected_id !== $_nav_menu_selected_id ) {
   383 					wp_redirect( admin_url( 'nav-menus.php?menu=' . intval( $_nav_menu_selected_id ) ) );
   427 					wp_redirect( admin_url( 'nav-menus.php?menu=' . intval( $_nav_menu_selected_id ) ) );
   384 					exit();
   428 					exit;
   385 				}
   429 				}
   386 			}
   430 			}
   387 		}
   431 		}
       
   432 
   388 		break;
   433 		break;
       
   434 
   389 	case 'locations':
   435 	case 'locations':
   390 		if ( ! $num_locations ) {
   436 		if ( ! $num_locations ) {
   391 			wp_redirect( admin_url( 'nav-menus.php' ) );
   437 			wp_redirect( admin_url( 'nav-menus.php' ) );
   392 			exit();
   438 			exit;
   393 		}
   439 		}
   394 
   440 
   395 		add_filter( 'screen_options_show_screen', '__return_false' );
   441 		add_filter( 'screen_options_show_screen', '__return_false' );
   396 
   442 
   397 		if ( isset( $_POST['menu-locations'] ) ) {
   443 		if ( isset( $_POST['menu-locations'] ) ) {
   398 			check_admin_referer( 'save-menu-locations' );
   444 			check_admin_referer( 'save-menu-locations' );
   399 
   445 
   400 			$new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
   446 			$new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
   401 			$menu_locations     = array_merge( $menu_locations, $new_menu_locations );
   447 			$menu_locations     = array_merge( $menu_locations, $new_menu_locations );
   402 			// Set menu locations
   448 			// Set menu locations.
   403 			set_theme_mod( 'nav_menu_locations', $menu_locations );
   449 			set_theme_mod( 'nav_menu_locations', $menu_locations );
   404 
   450 
   405 			$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Menu locations updated.' ) . '</p></div>';
   451 			$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Menu locations updated.' ) . '</p></div>';
   406 		}
   452 		}
       
   453 
   407 		break;
   454 		break;
   408 }
   455 }
   409 
   456 
   410 // Get all nav menus.
   457 // Get all nav menus.
   411 $nav_menus  = wp_get_nav_menus();
   458 $nav_menus  = wp_get_nav_menus();
   412 $menu_count = count( $nav_menus );
   459 $menu_count = count( $nav_menus );
   413 
   460 
   414 // Are we on the add new screen?
   461 // Are we on the add new screen?
   415 $add_new_screen = ( isset( $_GET['menu'] ) && 0 == $_GET['menu'] ) ? true : false;
   462 $add_new_screen = ( isset( $_GET['menu'] ) && 0 === (int) $_GET['menu'] ) ? true : false;
   416 
   463 
   417 $locations_screen = ( isset( $_GET['action'] ) && 'locations' == $_GET['action'] ) ? true : false;
   464 $locations_screen = ( isset( $_GET['action'] ) && 'locations' === $_GET['action'] ) ? true : false;
       
   465 
       
   466 $page_count = wp_count_posts( 'page' );
   418 
   467 
   419 /*
   468 /*
   420  * If we have one theme location, and zero menus, we take them right
   469  * If we have one theme location, and zero menus, we take them right
   421  * into editing their first menu.
   470  * into editing their first menu.
   422  */
   471  */
   423 $page_count                  = wp_count_posts( 'page' );
   472 if ( 1 === count( get_registered_nav_menus() ) && ! $add_new_screen
   424 $one_theme_location_no_menus = ( 1 == count( get_registered_nav_menus() ) && ! $add_new_screen && empty( $nav_menus ) && ! empty( $page_count->publish ) ) ? true : false;
   473 	&& empty( $nav_menus ) && ! empty( $page_count->publish )
       
   474 ) {
       
   475 	$one_theme_location_no_menus = true;
       
   476 } else {
       
   477 	$one_theme_location_no_menus = false;
       
   478 }
   425 
   479 
   426 $nav_menus_l10n = array(
   480 $nav_menus_l10n = array(
   427 	'oneThemeLocationNoMenus' => $one_theme_location_no_menus,
   481 	'oneThemeLocationNoMenus' => $one_theme_location_no_menus,
   428 	'moveUp'                  => __( 'Move up one' ),
   482 	'moveUp'                  => __( 'Move up one' ),
   429 	'moveDown'                => __( 'Move down one' ),
   483 	'moveDown'                => __( 'Move down one' ),
   430 	'moveToTop'               => __( 'Move to the top' ),
   484 	'moveToTop'               => __( 'Move to the top' ),
   431 	/* translators: %s: previous item name */
   485 	/* translators: %s: Previous item name. */
   432 	'moveUnder'               => __( 'Move under %s' ),
   486 	'moveUnder'               => __( 'Move under %s' ),
   433 	/* translators: %s: previous item name */
   487 	/* translators: %s: Previous item name. */
   434 	'moveOutFrom'             => __( 'Move out from under %s' ),
   488 	'moveOutFrom'             => __( 'Move out from under %s' ),
   435 	/* translators: %s: previous item name */
   489 	/* translators: %s: Previous item name. */
   436 	'under'                   => __( 'Under %s' ),
   490 	'under'                   => __( 'Under %s' ),
   437 	/* translators: %s: previous item name */
   491 	/* translators: %s: Previous item name. */
   438 	'outFrom'                 => __( 'Out from under %s' ),
   492 	'outFrom'                 => __( 'Out from under %s' ),
   439 	/* translators: 1: item name, 2: item position, 3: total number of items */
   493 	/* translators: 1: Item name, 2: Item position, 3: Total number of items. */
   440 	'menuFocus'               => __( '%1$s. Menu item %2$d of %3$d.' ),
   494 	'menuFocus'               => __( '%1$s. Menu item %2$d of %3$d.' ),
   441 	/* translators: 1: item name, 2: item position, 3: parent item name */
   495 	/* translators: 1: Item name, 2: Item position, 3: Parent item name. */
   442 	'subMenuFocus'            => __( '%1$s. Sub item number %2$d under %3$s.' ),
   496 	'subMenuFocus'            => __( '%1$s. Sub item number %2$d under %3$s.' ),
   443 );
   497 );
   444 wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n );
   498 wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n );
   445 
   499 
   446 /*
   500 /*
   447  * Redirect to add screen if there are no menus and this users has either zero,
   501  * Redirect to add screen if there are no menus and this users has either zero,
   448  * or more than 1 theme locations.
   502  * or more than 1 theme locations.
   449  */
   503  */
   450 if ( 0 == $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus ) {
   504 if ( 0 === $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus ) {
   451 	wp_redirect( admin_url( 'nav-menus.php?action=edit&menu=0' ) );
   505 	wp_redirect( admin_url( 'nav-menus.php?action=edit&menu=0' ) );
   452 }
   506 }
   453 
   507 
   454 // Get recently edited nav menu.
   508 // Get recently edited nav menu.
   455 $recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) );
   509 $recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) );
   461 if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) {
   515 if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) ) {
   462 	$nav_menu_selected_id = $recently_edited;
   516 	$nav_menu_selected_id = $recently_edited;
   463 }
   517 }
   464 
   518 
   465 // On deletion of menu, if another menu exists, show it.
   519 // On deletion of menu, if another menu exists, show it.
   466 if ( ! $add_new_screen && 0 < $menu_count && isset( $_GET['action'] ) && 'delete' == $_GET['action'] ) {
   520 if ( ! $add_new_screen && $menu_count > 0 && isset( $_GET['action'] ) && 'delete' === $_GET['action'] ) {
   467 	$nav_menu_selected_id = $nav_menus[0]->term_id;
   521 	$nav_menu_selected_id = $nav_menus[0]->term_id;
   468 }
   522 }
   469 
   523 
   470 // Set $nav_menu_selected_id to 0 if no menus.
   524 // Set $nav_menu_selected_id to 0 if no menus.
   471 if ( $one_theme_location_no_menus ) {
   525 if ( $one_theme_location_no_menus ) {
   472 	$nav_menu_selected_id = 0;
   526 	$nav_menu_selected_id = 0;
   473 } elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) {
   527 } elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) {
   474 	// if we have no selection yet, and we have menus, set to the first one in the list.
   528 	// If we have no selection yet, and we have menus, set to the first one in the list.
   475 	$nav_menu_selected_id = $nav_menus[0]->term_id;
   529 	$nav_menu_selected_id = $nav_menus[0]->term_id;
   476 }
   530 }
   477 
   531 
   478 // Update the user's setting.
   532 // Update the user's setting.
   479 if ( $nav_menu_selected_id != $recently_edited && is_nav_menu( $nav_menu_selected_id ) ) {
   533 if ( $nav_menu_selected_id !== $recently_edited && is_nav_menu( $nav_menu_selected_id ) ) {
   480 	update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id );
   534 	update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id );
   481 }
   535 }
   482 
   536 
   483 // If there's a menu, get its name.
   537 // If there's a menu, get its name.
   484 if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
   538 if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
   527 
   581 
   528 wp_nav_menu_setup();
   582 wp_nav_menu_setup();
   529 wp_initial_nav_menu_meta_boxes();
   583 wp_initial_nav_menu_meta_boxes();
   530 
   584 
   531 if ( ! current_theme_supports( 'menus' ) && ! $num_locations ) {
   585 if ( ! current_theme_supports( 'menus' ) && ! $num_locations ) {
   532 	$messages[] = '<div id="message" class="updated"><p>' . sprintf( __( 'Your theme does not natively support menus, but you can use them in sidebars by adding a &#8220;Navigation Menu&#8221; widget on the <a href="%s">Widgets</a> screen.' ), admin_url( 'widgets.php' ) ) . '</p></div>';
   586 	$messages[] = '<div id="message" class="updated"><p>' . sprintf(
   533 }
   587 		/* translators: %s: URL to Widgets screen. */
   534 
   588 		__( 'Your theme does not natively support menus, but you can use them in sidebars by adding a &#8220;Navigation Menu&#8221; widget on the <a href="%s">Widgets</a> screen.' ),
   535 if ( ! $locations_screen ) : // Main tab
   589 		admin_url( 'widgets.php' )
   536 	$overview = '<p>' . __( 'This screen is used for managing your navigation menus.' ) . '</p>';
   590 	) . '</p></div>';
   537 	/* translators: 1: Widgets admin screen URL, 2 and 3: The name of the default themes */
   591 }
   538 	$overview .= '<p>' . sprintf( __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a &#8220;Navigation Menu&#8221; 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.' ), admin_url( 'widgets.php' ), 'Twenty Seventeen', 'Twenty Nineteen' ) . '</p>';
   592 
       
   593 if ( ! $locations_screen ) : // Main tab.
       
   594 	$overview  = '<p>' . __( 'This screen is used for managing your navigation menus.' ) . '</p>';
       
   595 	$overview .= '<p>' . sprintf(
       
   596 		/* 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 &#8220;Navigation Menu&#8221; 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' ),
       
   599 		'Twenty Nineteen',
       
   600 		'Twenty Twenty'
       
   601 	) . '</p>';
   539 	$overview .= '<p>' . __( 'From this screen you can:' ) . '</p>';
   602 	$overview .= '<p>' . __( 'From this screen you can:' ) . '</p>';
   540 	$overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>';
   603 	$overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>';
   541 	$overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>';
   604 	$overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>';
   542 
   605 
   543 	get_current_screen()->add_help_tab(
   606 	get_current_screen()->add_help_tab(
   573 			'id'      => 'editing-menus',
   636 			'id'      => 'editing-menus',
   574 			'title'   => __( 'Editing Menus' ),
   637 			'title'   => __( 'Editing Menus' ),
   575 			'content' => $editing_menus,
   638 			'content' => $editing_menus,
   576 		)
   639 		)
   577 	);
   640 	);
   578 else : // Locations Tab.
   641 else : // Locations tab.
   579 	$locations_overview  = '<p>' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '</p>';
   642 	$locations_overview  = '<p>' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '</p>';
   580 	$locations_overview .= '<ul><li>' . __( 'To assign menus to one or more theme locations, <strong>select a menu from each location&#8217;s drop down.</strong> When you&#8217;re finished, <strong>click Save Changes</strong>' ) . '</li>';
   643 	$locations_overview .= '<ul><li>' . __( 'To assign menus to one or more theme locations, <strong>select a menu from each location&#8217;s drop down.</strong> When you&#8217;re finished, <strong>click Save Changes</strong>' ) . '</li>';
   581 	$locations_overview .= '<li>' . __( 'To edit a menu currently assigned to a theme location, <strong>click the adjacent &#8217;Edit&#8217; link</strong>' ) . '</li>';
   644 	$locations_overview .= '<li>' . __( 'To edit a menu currently assigned to a theme location, <strong>click the adjacent &#8217;Edit&#8217; link</strong>' ) . '</li>';
   582 	$locations_overview .= '<li>' . __( 'To add a new menu instead of assigning an existing one, <strong>click the &#8217;Use new menu&#8217; link</strong>. Your new menu will be automatically assigned to that theme location' ) . '</li></ul>';
   645 	$locations_overview .= '<li>' . __( 'To add a new menu instead of assigning an existing one, <strong>click the &#8217;Use new menu&#8217; link</strong>. Your new menu will be automatically assigned to that theme location' ) . '</li></ul>';
   583 
   646 
   590 	);
   653 	);
   591 endif;
   654 endif;
   592 
   655 
   593 get_current_screen()->set_help_sidebar(
   656 get_current_screen()->set_help_sidebar(
   594 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   657 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   595 	'<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Menus_Screen">Documentation on Menus</a>' ) . '</p>' .
   658 	'<p>' . __( '<a href="https://wordpress.org/support/article/appearance-menus-screen/">Documentation on Menus</a>' ) . '</p>' .
   596 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   659 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   597 );
   660 );
   598 
   661 
   599 // Get the admin header.
   662 // Get the admin header.
   600 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   663 require_once ABSPATH . 'wp-admin/admin-header.php';
   601 ?>
   664 ?>
   602 <div class="wrap">
   665 <div class="wrap">
   603 	<h1 class="wp-heading-inline"><?php echo esc_html( __( 'Menus' ) ); ?></h1>
   666 	<h1 class="wp-heading-inline"><?php echo esc_html( __( 'Menus' ) ); ?></h1>
   604 	<?php
   667 	<?php
   605 	if ( current_user_can( 'customize' ) ) :
   668 	if ( current_user_can( 'customize' ) ) :
   619 		);
   682 		);
   620 	endif;
   683 	endif;
   621 
   684 
   622 	$nav_tab_active_class = '';
   685 	$nav_tab_active_class = '';
   623 	$nav_aria_current     = '';
   686 	$nav_aria_current     = '';
   624 	if ( ! isset( $_GET['action'] ) || isset( $_GET['action'] ) && 'locations' != $_GET['action'] ) {
   687 
       
   688 	if ( ! isset( $_GET['action'] ) || isset( $_GET['action'] ) && 'locations' !== $_GET['action'] ) {
   625 		$nav_tab_active_class = ' nav-tab-active';
   689 		$nav_tab_active_class = ' nav-tab-active';
   626 		$nav_aria_current     = ' aria-current="page"';
   690 		$nav_aria_current     = ' aria-current="page"';
   627 	}
   691 	}
   628 	?>
   692 	?>
   629 
   693 
   633 		<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>
   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>
   634 		<?php
   698 		<?php
   635 		if ( $num_locations && $menu_count ) {
   699 		if ( $num_locations && $menu_count ) {
   636 			$active_tab_class = '';
   700 			$active_tab_class = '';
   637 			$aria_current     = '';
   701 			$aria_current     = '';
       
   702 
   638 			if ( $locations_screen ) {
   703 			if ( $locations_screen ) {
   639 				$active_tab_class = ' nav-tab-active';
   704 				$active_tab_class = ' nav-tab-active';
   640 				$aria_current     = ' aria-current="page"';
   705 				$aria_current     = ' aria-current="page"';
   641 			}
   706 			}
   642 			?>
   707 			?>
   650 		echo $message . "\n";
   715 		echo $message . "\n";
   651 	endforeach;
   716 	endforeach;
   652 	?>
   717 	?>
   653 	<?php
   718 	<?php
   654 	if ( $locations_screen ) :
   719 	if ( $locations_screen ) :
   655 		if ( 1 == $num_locations ) {
   720 		if ( 1 === $num_locations ) {
   656 			echo '<p>' . __( 'Your theme supports one menu. Select which menu you would like to use.' ) . '</p>';
   721 			echo '<p>' . __( 'Your theme supports one menu. Select which menu you would like to use.' ) . '</p>';
   657 		} else {
   722 		} else {
   658 			echo '<p>' . sprintf( _n( 'Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>';
   723 			echo '<p>' . sprintf(
       
   724 				/* translators: %s: Number of menus. */
       
   725 				_n(
       
   726 					'Your theme supports %s menu. Select which menu appears in each location.',
       
   727 					'Your theme supports %s menus. Select which menu appears in each location.',
       
   728 					$num_locations
       
   729 				),
       
   730 				number_format_i18n( $num_locations )
       
   731 			) . '</p>';
   659 		}
   732 		}
   660 		?>
   733 		?>
   661 	<div id="menu-locations-wrap">
   734 	<div id="menu-locations-wrap">
   662 		<form method="post" action="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>">
   735 		<form method="post" action="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>">
   663 			<table class="widefat fixed" id="menu-locations-table">
   736 			<table class="widefat fixed" id="menu-locations-table">
   675 							<select name="menu-locations[<?php echo $_location; ?>]" id="locations-<?php echo $_location; ?>">
   748 							<select name="menu-locations[<?php echo $_location; ?>]" id="locations-<?php echo $_location; ?>">
   676 								<option value="0"><?php printf( '&mdash; %s &mdash;', esc_html__( 'Select a Menu' ) ); ?></option>
   749 								<option value="0"><?php printf( '&mdash; %s &mdash;', esc_html__( 'Select a Menu' ) ); ?></option>
   677 								<?php
   750 								<?php
   678 								foreach ( $nav_menus as $menu ) :
   751 								foreach ( $nav_menus as $menu ) :
   679 									$data_orig = '';
   752 									$data_orig = '';
   680 									$selected  = isset( $menu_locations[ $_location ] ) && $menu_locations[ $_location ] == $menu->term_id;
   753 									$selected  = isset( $menu_locations[ $_location ] ) && $menu_locations[ $_location ] === $menu->term_id;
       
   754 
   681 									if ( $selected ) {
   755 									if ( $selected ) {
   682 										$data_orig = 'data-orig="true"';
   756 										$data_orig = 'data-orig="true"';
   683 									}
   757 									}
   684 									?>
   758 									?>
   685 									<option <?php echo $data_orig; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>">
   759 									<option <?php echo $data_orig; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>">
   686 										<?php echo wp_html_excerpt( $menu->name, 40, '&hellip;' ); ?>
   760 										<?php echo wp_html_excerpt( $menu->name, 40, '&hellip;' ); ?>
   687 									</option>
   761 									</option>
   688 								<?php endforeach; ?>
   762 								<?php endforeach; ?>
   689 							</select>
   763 							</select>
   690 							<div class="locations-row-links">
   764 							<div class="locations-row-links">
   691 								<?php if ( isset( $menu_locations[ $_location ] ) && 0 != $menu_locations[ $_location ] ) : ?>
   765 								<?php if ( isset( $menu_locations[ $_location ] ) && 0 !== $menu_locations[ $_location ] ) : ?>
   692 								<span class="locations-edit-menu-link">
   766 								<span class="locations-edit-menu-link">
   693 									<a href="
   767 									<a href="
   694 									<?php
   768 									<?php
   695 									echo esc_url(
   769 									echo esc_url(
   696 										add_query_arg(
   770 										add_query_arg(
   726 									</a>
   800 									</a>
   727 								</span>
   801 								</span>
   728 							</div><!-- .locations-row-links -->
   802 							</div><!-- .locations-row-links -->
   729 						</td><!-- .menu-location-menus -->
   803 						</td><!-- .menu-location-menus -->
   730 					</tr><!-- .menu-locations-row -->
   804 					</tr><!-- .menu-locations-row -->
   731 				<?php } // foreach ?>
   805 				<?php } // End foreach. ?>
   732 				</tbody>
   806 				</tbody>
   733 			</table>
   807 			</table>
   734 			<p class="button-controls wp-clearfix"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p>
   808 			<p class="button-controls wp-clearfix"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p>
   735 			<?php wp_nonce_field( 'save-menu-locations' ); ?>
   809 			<?php wp_nonce_field( 'save-menu-locations' ); ?>
   736 			<input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
   810 			<input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
   753 		</span><!-- /first-menu-message -->
   827 		</span><!-- /first-menu-message -->
   754 		<?php elseif ( $menu_count < 2 ) : ?>
   828 		<?php elseif ( $menu_count < 2 ) : ?>
   755 		<span class="add-edit-menu-action">
   829 		<span class="add-edit-menu-action">
   756 			<?php
   830 			<?php
   757 			printf(
   831 			printf(
       
   832 				/* translators: %s: URL to create a new menu. */
   758 				__( 'Edit your menu below, or <a href="%s">create a new menu</a>. Don&#8217;t forget to save your changes!' ),
   833 				__( 'Edit your menu below, or <a href="%s">create a new menu</a>. Don&#8217;t forget to save your changes!' ),
   759 				esc_url(
   834 				esc_url(
   760 					add_query_arg(
   835 					add_query_arg(
   761 						array(
   836 						array(
   762 							'action' => 'edit',
   837 							'action' => 'edit',
   780 				<?php foreach ( (array) $nav_menus as $_nav_menu ) : ?>
   855 				<?php foreach ( (array) $nav_menus as $_nav_menu ) : ?>
   781 					<option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>>
   856 					<option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>>
   782 						<?php
   857 						<?php
   783 						echo esc_html( $_nav_menu->truncated_name );
   858 						echo esc_html( $_nav_menu->truncated_name );
   784 
   859 
   785 						if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) {
   860 						if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations, true ) ) {
   786 							$locations_assigned_to_this_menu = array();
   861 							$locations_assigned_to_this_menu = array();
   787 							foreach ( array_keys( $menu_locations, $_nav_menu->term_id ) as $menu_location_key ) {
   862 
       
   863 							foreach ( array_keys( $menu_locations, $_nav_menu->term_id, true ) as $menu_location_key ) {
   788 								if ( isset( $locations[ $menu_location_key ] ) ) {
   864 								if ( isset( $locations[ $menu_location_key ] ) ) {
   789 									$locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
   865 									$locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
   790 								}
   866 								}
   791 							}
   867 							}
   792 
   868 
   795 							 *
   871 							 *
   796 							 * @since 3.6.0
   872 							 * @since 3.6.0
   797 							 *
   873 							 *
   798 							 * @param int $locations Number of menu locations to list. Default 3.
   874 							 * @param int $locations Number of menu locations to list. Default 3.
   799 							 */
   875 							 */
   800 							$assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) ) );
   876 							$locations_listed_per_menu = absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) );
       
   877 
       
   878 							$assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, $locations_listed_per_menu );
   801 
   879 
   802 							// Adds ellipses following the number of locations defined in $assigned_locations.
   880 							// Adds ellipses following the number of locations defined in $assigned_locations.
   803 							if ( ! empty( $assigned_locations ) ) {
   881 							if ( ! empty( $assigned_locations ) ) {
   804 								printf(
   882 								printf(
   805 									' (%1$s%2$s)',
   883 									' (%1$s%2$s)',
   814 			</select>
   892 			</select>
   815 			<span class="submit-btn"><input type="submit" class="button" value="<?php esc_attr_e( 'Select' ); ?>"></span>
   893 			<span class="submit-btn"><input type="submit" class="button" value="<?php esc_attr_e( 'Select' ); ?>"></span>
   816 			<span class="add-new-menu-action">
   894 			<span class="add-new-menu-action">
   817 				<?php
   895 				<?php
   818 				printf(
   896 				printf(
       
   897 					/* translators: %s: URL to create a new menu. */
   819 					__( 'or <a href="%s">create a new menu</a>. Don&#8217;t forget to save your changes!' ),
   898 					__( 'or <a href="%s">create a new menu</a>. Don&#8217;t forget to save your changes!' ),
   820 					esc_url(
   899 					esc_url(
   821 						add_query_arg(
   900 						add_query_arg(
   822 							array(
   901 							array(
   823 								'action' => 'edit',
   902 								'action' => 'edit',
   833 		</form>
   912 		</form>
   834 			<?php
   913 			<?php
   835 		endif;
   914 		endif;
   836 
   915 
   837 		$metabox_holder_disabled_class = '';
   916 		$metabox_holder_disabled_class = '';
   838 		if ( isset( $_GET['menu'] ) && '0' == $_GET['menu'] ) {
   917 
       
   918 		if ( isset( $_GET['menu'] ) && 0 === (int) $_GET['menu'] ) {
   839 			$metabox_holder_disabled_class = ' metabox-holder-disabled';
   919 			$metabox_holder_disabled_class = ' metabox-holder-disabled';
   840 		}
   920 		}
   841 		?>
   921 		?>
   842 	</div><!-- /manage-menus -->
   922 	</div><!-- /manage-menus -->
   843 	<div id="nav-menus-frame" class="wp-clearfix">
   923 	<div id="nav-menus-frame" class="wp-clearfix">
   855 
   935 
   856 	</div><!-- /#menu-settings-column -->
   936 	</div><!-- /#menu-settings-column -->
   857 	<div id="menu-management-liquid">
   937 	<div id="menu-management-liquid">
   858 		<div id="menu-management">
   938 		<div id="menu-management">
   859 			<form id="update-nav-menu" method="post" enctype="multipart/form-data">
   939 			<form id="update-nav-menu" method="post" enctype="multipart/form-data">
   860 			<?php
       
   861 				$new_screen_class = '';
       
   862 			if ( $add_new_screen ) {
       
   863 				$new_screen_class = 'blank-slate';
       
   864 			}
       
   865 			?>
       
   866 				<h2><?php _e( 'Menu structure' ); ?></h2>
   940 				<h2><?php _e( 'Menu structure' ); ?></h2>
   867 				<div class="menu-edit <?php echo $new_screen_class; ?>">
   941 				<div class="menu-edit">
   868 					<input type="hidden" name="nav-menu-data">
   942 					<input type="hidden" name="nav-menu-data">
   869 					<?php
   943 					<?php
   870 					wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
   944 					wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
   871 					wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
   945 					wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
   872 					wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' );
   946 					wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' );
   894 						</div><!-- END .major-publishing-actions -->
   968 						</div><!-- END .major-publishing-actions -->
   895 					</div><!-- END .nav-menu-header -->
   969 					</div><!-- END .nav-menu-header -->
   896 					<div id="post-body">
   970 					<div id="post-body">
   897 						<div id="post-body-content" class="wp-clearfix">
   971 						<div id="post-body-content" class="wp-clearfix">
   898 							<?php if ( ! $add_new_screen ) : ?>
   972 							<?php if ( ! $add_new_screen ) : ?>
       
   973 
   899 								<?php
   974 								<?php
   900 								$hide_style = '';
   975 								$hide_style = '';
   901 								if ( isset( $menu_items ) && 0 == count( $menu_items ) ) {
   976 
       
   977 								if ( isset( $menu_items ) && 0 === count( $menu_items ) ) {
   902 									$hide_style = 'style="display: none;"';
   978 									$hide_style = 'style="display: none;"';
   903 								}
   979 								}
   904 								$starter_copy = ( $one_theme_location_no_menus ) ? __( 'Edit your default menu by adding or removing items. Drag each item into the order you prefer. Click Create Menu to save your changes.' ) : __( 'Drag each item into the order you prefer. Click the arrow on the right of the item to reveal additional configuration options.' );
   980 
       
   981 								if ( $one_theme_location_no_menus ) {
       
   982 									$starter_copy = __( 'Edit your default menu by adding or removing items. Drag the items into the order you prefer. Click Create Menu to save your changes.' );
       
   983 								} else {
       
   984 									$starter_copy = __( 'Drag the items into the order you prefer. Click the arrow on the right of the item to reveal additional configuration options.' );
       
   985 								}
   905 								?>
   986 								?>
   906 							<div class="drag-instructions post-body-plain" <?php echo $hide_style; ?>>
   987 								<div class="drag-instructions post-body-plain" <?php echo $hide_style; ?>>
   907 								<p><?php echo $starter_copy; ?></p>
   988 									<p><?php echo $starter_copy; ?></p>
   908 							</div>
   989 								</div>
       
   990 
   909 								<?php
   991 								<?php
   910 								if ( isset( $edit_markup ) && ! is_wp_error( $edit_markup ) ) {
   992 								if ( isset( $edit_markup ) && ! is_wp_error( $edit_markup ) ) {
   911 									echo $edit_markup;
   993 									echo $edit_markup;
   912 								} else {
   994 								} else {
   913 									?>
   995 									?>
   914 							<ul class="menu" id="menu-to-edit"></ul>
   996 									<ul class="menu" id="menu-to-edit"></ul>
   915 								<?php } ?>
   997 								<?php } ?>
       
   998 
   916 							<?php endif; ?>
   999 							<?php endif; ?>
       
  1000 
   917 							<?php if ( $add_new_screen ) : ?>
  1001 							<?php if ( $add_new_screen ) : ?>
   918 								<p class="post-body-plain" id="menu-name-desc"><?php _e( 'Give your menu a name, then click Create Menu.' ); ?></p>
  1002 								<p class="post-body-plain" id="menu-name-desc"><?php _e( 'Give your menu a name, then click Create Menu.' ); ?></p>
   919 								<?php if ( isset( $_GET['use-location'] ) ) : ?>
  1003 								<?php if ( isset( $_GET['use-location'] ) ) : ?>
   920 									<input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" />
  1004 									<input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" />
   921 								<?php endif; ?>
  1005 								<?php endif; ?>
       
  1006 
   922 								<?php
  1007 								<?php
   923 								endif;
  1008 							endif;
   924 
  1009 
   925 								$no_menus_style = '';
  1010 							$no_menus_style = '';
       
  1011 
   926 							if ( $one_theme_location_no_menus ) {
  1012 							if ( $one_theme_location_no_menus ) {
   927 								$no_menus_style = 'style="display: none;"';
  1013 								$no_menus_style = 'style="display: none;"';
   928 							}
  1014 							}
   929 							?>
  1015 							?>
   930 							<div class="menu-settings" <?php echo $no_menus_style; ?>>
  1016 							<div class="menu-settings" <?php echo $no_menus_style; ?>>
   931 								<h3><?php _e( 'Menu Settings' ); ?></h3>
  1017 								<h3><?php _e( 'Menu Settings' ); ?></h3>
   932 								<?php
  1018 								<?php
   933 								if ( ! isset( $auto_add ) ) {
  1019 								if ( ! isset( $auto_add ) ) {
   934 									$auto_add = get_option( 'nav_menu_options' );
  1020 									$auto_add = get_option( 'nav_menu_options' );
       
  1021 
   935 									if ( ! isset( $auto_add['auto_add'] ) ) {
  1022 									if ( ! isset( $auto_add['auto_add'] ) ) {
   936 										$auto_add = false;
  1023 										$auto_add = false;
   937 									} elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'] ) ) {
  1024 									} elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'], true ) ) {
   938 										$auto_add = true;
  1025 										$auto_add = true;
   939 									} else {
  1026 									} else {
   940 										$auto_add = false;
  1027 										$auto_add = false;
   941 									}
  1028 									}
   942 								}
  1029 								}
   951 
  1038 
   952 								<?php if ( current_theme_supports( 'menus' ) ) : ?>
  1039 								<?php if ( current_theme_supports( 'menus' ) ) : ?>
   953 
  1040 
   954 									<fieldset class="menu-settings-group menu-theme-locations">
  1041 									<fieldset class="menu-settings-group menu-theme-locations">
   955 										<legend class="menu-settings-group-name howto"><?php _e( 'Display location' ); ?></legend>
  1042 										<legend class="menu-settings-group-name howto"><?php _e( 'Display location' ); ?></legend>
   956 										<?php foreach ( $locations as $location => $description ) : ?>
  1043 										<?php
   957 										<div class="menu-settings-input checkbox-input">
  1044 										foreach ( $locations as $location => $description ) :
   958 											<input type="checkbox"<?php checked( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id ); ?> name="menu-locations[<?php echo esc_attr( $location ); ?>]" id="locations-<?php echo esc_attr( $location ); ?>" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
  1045 											$checked = isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] === $nav_menu_selected_id;
   959 											<label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label>
  1046 											?>
   960 											<?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] != $nav_menu_selected_id ) : ?>
  1047 											<div class="menu-settings-input checkbox-input">
   961 												<span class="theme-location-set">
  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 ); ?>" />
   962 												<?php
  1049 												<label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label>
   963 													printf(
  1050 												<?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] !== $nav_menu_selected_id ) : ?>
   964 														/* translators: %s: menu name */
  1051 													<span class="theme-location-set">
   965 														_x( '(Currently set to: %s)', 'menu location' ),
  1052 													<?php
   966 														wp_get_nav_menu_object( $menu_locations[ $location ] )->name
  1053 														printf(
   967 													);
  1054 															/* translators: %s: Menu name. */
   968 												?>
  1055 															_x( '(Currently set to: %s)', 'menu location' ),
   969 												</span>
  1056 															wp_get_nav_menu_object( $menu_locations[ $location ] )->name
   970 											<?php endif; ?>
  1057 														);
   971 										</div>
  1058 													?>
       
  1059 													</span>
       
  1060 												<?php endif; ?>
       
  1061 											</div>
   972 										<?php endforeach; ?>
  1062 										<?php endforeach; ?>
   973 									</fieldset>
  1063 									</fieldset>
   974 
  1064 
   975 								<?php endif; ?>
  1065 								<?php endif; ?>
   976 
  1066 
   977 							</div>
  1067 							</div>
   978 						</div><!-- /#post-body-content -->
  1068 						</div><!-- /#post-body-content -->
   979 					</div><!-- /#post-body -->
  1069 					</div><!-- /#post-body -->
   980 					<div id="nav-menu-footer">
  1070 					<div id="nav-menu-footer">
   981 						<div class="major-publishing-actions wp-clearfix">
  1071 						<div class="major-publishing-actions wp-clearfix">
   982 							<?php if ( 0 != $menu_count && ! $add_new_screen ) : ?>
  1072 							<?php if ( $menu_count > 0 ) : ?>
   983 							<span class="delete-action">
  1073 
   984 								<a class="submitdelete deletion menu-delete" href="
  1074 								<?php if ( $add_new_screen ) : ?>
   985 								<?php
  1075 								<span class="cancel-action">
   986 								echo esc_url(
  1076 									<a class="submitcancel cancellation menu-cancel" href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php _e( 'Cancel' ); ?></a>
   987 									wp_nonce_url(
  1077 								</span><!-- END .cancel-action -->
   988 										add_query_arg(
  1078 								<?php else : ?>
   989 											array(
  1079 								<span class="delete-action">
   990 												'action' => 'delete',
  1080 									<a class="submitdelete deletion menu-delete" href="
   991 												'menu'   => $nav_menu_selected_id,
  1081 									<?php
       
  1082 									echo esc_url(
       
  1083 										wp_nonce_url(
       
  1084 											add_query_arg(
       
  1085 												array(
       
  1086 													'action' => 'delete',
       
  1087 													'menu' => $nav_menu_selected_id,
       
  1088 												),
       
  1089 												admin_url( 'nav-menus.php' )
   992 											),
  1090 											),
   993 											admin_url( 'nav-menus.php' )
  1091 											'delete-nav_menu-' . $nav_menu_selected_id
   994 										),
  1092 										)
   995 										'delete-nav_menu-' . $nav_menu_selected_id
  1093 									);
   996 									)
  1094 									?>
   997 								);
  1095 									"><?php _e( 'Delete Menu' ); ?></a>
   998 								?>
  1096 								</span><!-- END .delete-action -->
   999 								"><?php _e( 'Delete Menu' ); ?></a>
  1097 								<?php endif; ?>
  1000 							</span><!-- END .delete-action -->
  1098 
  1001 							<?php endif; ?>
  1099 							<?php endif; ?>
  1002 							<div class="publishing-action">
  1100 							<div class="publishing-action">
  1003 								<?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_footer' ) ); ?>
  1101 								<?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_footer' ) ); ?>
  1004 							</div><!-- END .publishing-action -->
  1102 							</div><!-- END .publishing-action -->
  1005 						</div><!-- END .major-publishing-actions -->
  1103 						</div><!-- END .major-publishing-actions -->
  1009 		</div><!-- /#menu-management -->
  1107 		</div><!-- /#menu-management -->
  1010 	</div><!-- /#menu-management-liquid -->
  1108 	</div><!-- /#menu-management-liquid -->
  1011 	</div><!-- /#nav-menus-frame -->
  1109 	</div><!-- /#nav-menus-frame -->
  1012 	<?php endif; ?>
  1110 	<?php endif; ?>
  1013 </div><!-- /.wrap-->
  1111 </div><!-- /.wrap-->
  1014 <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>
  1112 <?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>