wp/wp-admin/nav-menus.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    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 // Permissions Check
    21 // Permissions Check
    22 if ( ! current_user_can('edit_theme_options') )
    22 if ( ! current_user_can( 'edit_theme_options' ) ) {
    23 	wp_die( __( 'Cheatin’ uh?' ), 403 );
    23 	wp_die(
       
    24 		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
       
    25 		'<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
       
    26 		403
       
    27 	);
       
    28 }
    24 
    29 
    25 wp_enqueue_script( 'nav-menu' );
    30 wp_enqueue_script( 'nav-menu' );
    26 
    31 
    27 if ( wp_is_mobile() )
    32 if ( wp_is_mobile() )
    28 	wp_enqueue_script( 'jquery-touch-punch' );
    33 	wp_enqueue_script( 'jquery-touch-punch' );
    41 $menu_locations = get_nav_menu_locations();
    46 $menu_locations = get_nav_menu_locations();
    42 $num_locations = count( array_keys( $locations ) );
    47 $num_locations = count( array_keys( $locations ) );
    43 
    48 
    44 // Allowed actions: add, update, delete
    49 // Allowed actions: add, update, delete
    45 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
    50 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
       
    51 
       
    52 /*
       
    53  * If a JSON blob of navigation menu data is found, expand it and inject it
       
    54  * into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134.
       
    55  */
       
    56 _wp_expand_nav_menu_post_data();
    46 
    57 
    47 switch ( $action ) {
    58 switch ( $action ) {
    48 	case 'add-menu-item':
    59 	case 'add-menu-item':
    49 		check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
    60 		check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
    50 		if ( isset( $_REQUEST['nav-menu-locations'] ) )
    61 		if ( isset( $_REQUEST['nav-menu-locations'] ) )
    65 				$menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
    76 				$menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
    66 
    77 
    67 				// Set up the data we need in one pass through the array of menu items.
    78 				// Set up the data we need in one pass through the array of menu items.
    68 				$dbids_to_orders = array();
    79 				$dbids_to_orders = array();
    69 				$orders_to_dbids = array();
    80 				$orders_to_dbids = array();
    70 				foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
    81 				foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
    71 					if ( isset( $ordered_menu_item_object->ID ) ) {
    82 					if ( isset( $ordered_menu_item_object->ID ) ) {
    72 						if ( isset( $ordered_menu_item_object->menu_order ) ) {
    83 						if ( isset( $ordered_menu_item_object->menu_order ) ) {
    73 							$dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
    84 							$dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
    74 							$orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
    85 							$orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
    75 						}
    86 						}
   138 				$menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
   149 				$menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
   139 
   150 
   140 				// Set up the data we need in one pass through the array of menu items.
   151 				// Set up the data we need in one pass through the array of menu items.
   141 				$dbids_to_orders = array();
   152 				$dbids_to_orders = array();
   142 				$orders_to_dbids = array();
   153 				$orders_to_dbids = array();
   143 				foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
   154 				foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
   144 					if ( isset( $ordered_menu_item_object->ID ) ) {
   155 					if ( isset( $ordered_menu_item_object->ID ) ) {
   145 						if ( isset( $ordered_menu_item_object->menu_order ) ) {
   156 						if ( isset( $ordered_menu_item_object->menu_order ) ) {
   146 							$dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
   157 							$dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
   147 							$orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
   158 							$orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
   148 						}
   159 						}
   352 				}
   363 				}
   353 			}
   364 			}
   354 
   365 
   355 			// Update menu items.
   366 			// Update menu items.
   356 			if ( ! is_wp_error( $_menu_object ) ) {
   367 			if ( ! is_wp_error( $_menu_object ) ) {
   357 				$messages = array_merge( $messages, wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) );
   368 				$messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) );
       
   369 
       
   370 				// If the menu ID changed, redirect to the new URL.
       
   371 				if ( $nav_menu_selected_id != $_nav_menu_selected_id ) {
       
   372 					wp_redirect( admin_url( 'nav-menus.php?menu=' . intval( $_nav_menu_selected_id ) ) );
       
   373 					exit();
       
   374 				}
   358 			}
   375 			}
   359 		}
   376 		}
   360 		break;
   377 		break;
   361 	case 'locations':
   378 	case 'locations':
   362 		if ( ! $num_locations ) {
   379 		if ( ! $num_locations ) {
   452 	$_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
   469 	$_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
   453 	$nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : '';
   470 	$nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : '';
   454 }
   471 }
   455 
   472 
   456 // Generate truncated menu names.
   473 // Generate truncated menu names.
   457 foreach( (array) $nav_menus as $key => $_nav_menu ) {
   474 foreach ( (array) $nav_menus as $key => $_nav_menu ) {
   458 	$nav_menus[$key]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '&hellip;' );
   475 	$nav_menus[$key]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '&hellip;' );
   459 }
   476 }
   460 
   477 
   461 // Retrieve menu locations.
   478 // Retrieve menu locations.
   462 if ( current_theme_supports( 'menus' ) ) {
   479 if ( current_theme_supports( 'menus' ) ) {
   465 }
   482 }
   466 
   483 
   467 /*
   484 /*
   468  * Ensure the user will be able to scroll horizontally
   485  * Ensure the user will be able to scroll horizontally
   469  * by adding a class for the max menu depth.
   486  * by adding a class for the max menu depth.
       
   487  *
       
   488  * @global int $_wp_nav_menu_max_depth
   470  */
   489  */
   471 global $_wp_nav_menu_max_depth;
   490 global $_wp_nav_menu_max_depth;
   472 $_wp_nav_menu_max_depth = 0;
   491 $_wp_nav_menu_max_depth = 0;
   473 
   492 
   474 // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth.
   493 // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth.
   475 if ( is_nav_menu( $nav_menu_selected_id ) ) {
   494 if ( is_nav_menu( $nav_menu_selected_id ) ) {
   476 	$menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'post_status' => 'any' ) );
   495 	$menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'post_status' => 'any' ) );
   477 	$edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id );
   496 	$edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id );
   478 }
   497 }
   479 
   498 
   480 function wp_nav_menu_max_depth($classes) {
   499 /**
       
   500  *
       
   501  * @global int $_wp_nav_menu_max_depth
       
   502  *
       
   503  * @param string $classes
       
   504  * @return string
       
   505  */
       
   506 function wp_nav_menu_max_depth( $classes ) {
   481 	global $_wp_nav_menu_max_depth;
   507 	global $_wp_nav_menu_max_depth;
   482 	return "$classes menu-max-depth-$_wp_nav_menu_max_depth";
   508 	return "$classes menu-max-depth-$_wp_nav_menu_max_depth";
   483 }
   509 }
   484 
   510 
   485 add_filter('admin_body_class', 'wp_nav_menu_max_depth');
   511 add_filter('admin_body_class', 'wp_nav_menu_max_depth');
   486 
   512 
   487 wp_nav_menu_setup();
   513 wp_nav_menu_setup();
   488 wp_initial_nav_menu_meta_boxes();
   514 wp_initial_nav_menu_meta_boxes();
   489 
   515 
   490 if ( ! current_theme_supports( 'menus' ) && ! $num_locations )
   516 if ( ! current_theme_supports( 'menus' ) && ! $num_locations )
   491 	$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;Custom Menu&#8221; widget on the <a href="%s">Widgets</a> screen.' ), admin_url( 'widgets.php' ) ) . '</p></div>';
   517 	$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>';
   492 
   518 
   493 if ( ! $locations_screen ) : // Main tab
   519 if ( ! $locations_screen ) : // Main tab
   494 	$overview  = '<p>' . __( 'This screen is used for managing your custom navigation menus.' ) . '</p>';
   520 	$overview  = '<p>' . __( 'This screen is used for managing your navigation menus.' ) . '</p>';
   495 	$overview .= '<p>' . sprintf( __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a &#8220;Custom Menu&#8221; widget on the <a href="%1$s">Widgets</a> screen. If your theme does not support the custom 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 Fifteen', 'Twenty Fourteen' ) . '</p>';
   521 	/* translators: 1: Widgets admin screen URL, 2 and 3: The name of the default themes */
       
   522 	$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 Sixteen', 'Twenty Seventeen' ) . '</p>';
   496 	$overview .= '<p>' . __( 'From this screen you can:' ) . '</p>';
   523 	$overview .= '<p>' . __( 'From this screen you can:' ) . '</p>';
   497 	$overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>';
   524 	$overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>';
   498 	$overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>';
   525 	$overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>';
   499 
   526 
   500 	get_current_screen()->add_help_tab( array(
   527 	get_current_screen()->add_help_tab( array(
   512 		'id'      => 'menu-management',
   539 		'id'      => 'menu-management',
   513 		'title'   => __( 'Menu Management' ),
   540 		'title'   => __( 'Menu Management' ),
   514 		'content' => $menu_management
   541 		'content' => $menu_management
   515 	) );
   542 	) );
   516 
   543 
   517 	$editing_menus  = '<p>' . __( 'Each custom menu may contain a mix of links to pages, categories, custom URLs or other content types. Menu links are added by selecting items from the expanding boxes in the left-hand column below.' ) . '</p>';
   544 	$editing_menus  = '<p>' . __( 'Each navigation menu may contain a mix of links to pages, categories, custom URLs or other content types. Menu links are added by selecting items from the expanding boxes in the left-hand column below.' ) . '</p>';
   518 	$editing_menus .= '<p>' . __( '<strong>Clicking the arrow to the right of any menu item</strong> in the editor will reveal a standard group of settings. Additional settings such as link target, CSS classes, link relationships, and link descriptions can be enabled and disabled via the Screen Options tab.' ) . '</p>';
   545 	$editing_menus .= '<p>' . __( '<strong>Clicking the arrow to the right of any menu item</strong> in the editor will reveal a standard group of settings. Additional settings such as link target, CSS classes, link relationships, and link descriptions can be enabled and disabled via the Screen Options tab.' ) . '</p>';
   519 	$editing_menus .= '<ul><li>' . __( 'Add one or several items at once by <strong>selecting the checkbox next to each item and clicking Add to Menu</strong>' ) . '</li>';
   546 	$editing_menus .= '<ul><li>' . __( 'Add one or several items at once by <strong>selecting the checkbox next to each item and clicking Add to Menu</strong>' ) . '</li>';
   520 	$editing_menus .= '<li>' . __( 'To add a custom link, <strong>expand the Custom Links section, enter a URL and link text, and click Add to Menu</strong>' ) .'</li>';
   547 	$editing_menus .= '<li>' . __( 'To add a custom link, <strong>expand the Custom Links section, enter a URL and link text, and click Add to Menu</strong>' ) .'</li>';
   521 	$editing_menus .= '<li>' . __( 'To reorganize menu items, <strong>drag and drop items with your mouse or use your keyboard</strong>. Drag or move a menu item a little to the right to make it a submenu' ) . '</li>';
   548 	$editing_menus .= '<li>' . __( 'To reorganize menu items, <strong>drag and drop items with your mouse or use your keyboard</strong>. Drag or move a menu item a little to the right to make it a submenu' ) . '</li>';
   522 	$editing_menus .= '<li>' . __( 'Delete a menu item by <strong>expanding it and clicking the Remove link</strong>' ) . '</li></ul>';
   549 	$editing_menus .= '<li>' . __( 'Delete a menu item by <strong>expanding it and clicking the Remove link</strong>' ) . '</li></ul>';
   539 	) );
   566 	) );
   540 endif;
   567 endif;
   541 
   568 
   542 get_current_screen()->set_help_sidebar(
   569 get_current_screen()->set_help_sidebar(
   543 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   570 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   544 	'<p>' . __('<a href="https://codex.wordpress.org/Appearance_Menus_Screen" target="_blank">Documentation on Menus</a>') . '</p>' .
   571 	'<p>' . __('<a href="https://codex.wordpress.org/Appearance_Menus_Screen">Documentation on Menus</a>') . '</p>' .
   545 	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
   572 	'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
   546 );
   573 );
   547 
   574 
   548 // Get the admin header.
   575 // Get the admin header.
   549 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   576 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   550 ?>
   577 ?>
   551 <div class="wrap">
   578 <div class="wrap">
   552 	<h2 class="nav-tab-wrapper">
   579 	<h1 class="wp-heading-inline"><?php echo esc_html( __( 'Menus' ) ); ?></h1>
       
   580 	<?php
       
   581 	if ( current_user_can( 'customize' ) ) :
       
   582 		$focus = $locations_screen ? array( 'section' => 'menu_locations' ) : array( 'panel' => 'nav_menus' );
       
   583 		printf(
       
   584 			' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>',
       
   585 			esc_url( add_query_arg( array(
       
   586 				array( 'autofocus' => $focus ),
       
   587 				'return' => urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ),
       
   588 			), admin_url( 'customize.php' ) ) ),
       
   589 			__( 'Manage with Live Preview' )
       
   590 		);
       
   591 	endif;
       
   592 	?>
       
   593 
       
   594 	<hr class="wp-header-end">
       
   595 
       
   596 	<h2 class="nav-tab-wrapper wp-clearfix">
   553 		<a href="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-tab<?php if ( ! isset( $_GET['action'] ) || isset( $_GET['action'] ) && 'locations' != $_GET['action'] ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Edit Menus' ); ?></a>
   597 		<a href="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-tab<?php if ( ! isset( $_GET['action'] ) || isset( $_GET['action'] ) && 'locations' != $_GET['action'] ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Edit Menus' ); ?></a>
   554 		<?php if ( $num_locations && $menu_count ) : ?>
   598 		<?php if ( $num_locations && $menu_count ) : ?>
   555 			<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>" class="nav-tab<?php if ( $locations_screen ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Manage Locations' ); ?></a>
   599 			<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>" class="nav-tab<?php if ( $locations_screen ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Manage Locations' ); ?></a>
   556 		<?php endif; ?>
   600 		<?php
       
   601 			endif;
       
   602 		?>
   557 	</h2>
   603 	</h2>
   558 	<?php
   604 	<?php
   559 	foreach( $messages as $message ) :
   605 	foreach ( $messages as $message ) :
   560 		echo $message . "\n";
   606 		echo $message . "\n";
   561 	endforeach;
   607 	endforeach;
   562 	?>
   608 	?>
   563 	<?php
   609 	<?php
   564 	if ( $locations_screen ) :
   610 	if ( $locations_screen ) :
   608 						</td><!-- .menu-location-menus -->
   654 						</td><!-- .menu-location-menus -->
   609 					</tr><!-- .menu-locations-row -->
   655 					</tr><!-- .menu-locations-row -->
   610 				<?php } // foreach ?>
   656 				<?php } // foreach ?>
   611 				</tbody>
   657 				</tbody>
   612 			</table>
   658 			</table>
   613 			<p class="button-controls"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p>
   659 			<p class="button-controls wp-clearfix"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p>
   614 			<?php wp_nonce_field( 'save-menu-locations' ); ?>
   660 			<?php wp_nonce_field( 'save-menu-locations' ); ?>
   615 			<input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
   661 			<input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
   616 		</form>
   662 		</form>
   617 	</div><!-- #menu-locations-wrap -->
   663 	</div><!-- #menu-locations-wrap -->
   618 	<?php
   664 	<?php
   629 			<?php printf( __( 'Edit your menu below, or <a href="%s">create a new menu</a>.' ), esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0 ), admin_url( 'nav-menus.php' ) ) ) ); ?>
   675 			<?php printf( __( 'Edit your menu below, or <a href="%s">create a new menu</a>.' ), esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0 ), admin_url( 'nav-menus.php' ) ) ) ); ?>
   630 		</span><!-- /add-edit-menu-action -->
   676 		</span><!-- /add-edit-menu-action -->
   631 		<?php else : ?>
   677 		<?php else : ?>
   632 			<form method="get" action="<?php echo admin_url( 'nav-menus.php' ); ?>">
   678 			<form method="get" action="<?php echo admin_url( 'nav-menus.php' ); ?>">
   633 			<input type="hidden" name="action" value="edit" />
   679 			<input type="hidden" name="action" value="edit" />
   634 			<label for="menu" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label>
   680 			<label for="select-menu-to-edit" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label>
   635 			<select name="menu" id="menu">
   681 			<select name="menu" id="select-menu-to-edit">
   636 				<?php if ( $add_new_screen ) : ?>
   682 				<?php if ( $add_new_screen ) : ?>
   637 					<option value="0" selected="selected"><?php _e( '&mdash; Select &mdash;' ); ?></option>
   683 					<option value="0" selected="selected"><?php _e( '&mdash; Select &mdash;' ); ?></option>
   638 				<?php endif; ?>
   684 				<?php endif; ?>
   639 				<?php foreach( (array) $nav_menus as $_nav_menu ) : ?>
   685 				<?php foreach ( (array) $nav_menus as $_nav_menu ) : ?>
   640 					<option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>>
   686 					<option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>>
   641 						<?php
   687 						<?php
   642 						echo esc_html( $_nav_menu->truncated_name ) ;
   688 						echo esc_html( $_nav_menu->truncated_name ) ;
   643 
   689 
   644 						if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) {
   690 						if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) {
   648 									$locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
   694 									$locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
   649 								}
   695 								}
   650 							}
   696 							}
   651 
   697 
   652 							/**
   698 							/**
   653 							 * Filter the number of locations listed per menu in the drop-down select.
   699 							 * Filters the number of locations listed per menu in the drop-down select.
   654 							 *
   700 							 *
   655 							 * @since 3.6.0
   701 							 * @since 3.6.0
   656 							 *
   702 							 *
   657 							 * @param int $locations Number of menu locations to list. Default 3.
   703 							 * @param int $locations Number of menu locations to list. Default 3.
   658 							 */
   704 							 */
   668 						}
   714 						}
   669 						?>
   715 						?>
   670 					</option>
   716 					</option>
   671 				<?php endforeach; ?>
   717 				<?php endforeach; ?>
   672 			</select>
   718 			</select>
   673 			<span class="submit-btn"><input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Select' ); ?>"></span>
   719 			<span class="submit-btn"><input type="submit" class="button" value="<?php esc_attr_e( 'Select' ); ?>"></span>
   674 			<span class="add-new-menu-action">
   720 			<span class="add-new-menu-action">
   675 				<?php printf( __( 'or <a href="%s">create a new menu</a>.' ), esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0 ), admin_url( 'nav-menus.php' ) ) ) ); ?>
   721 				<?php printf( __( 'or <a href="%s">create a new menu</a>.' ), esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0 ), admin_url( 'nav-menus.php' ) ) ) ); ?>
   676 			</span><!-- /add-new-menu-action -->
   722 			</span><!-- /add-new-menu-action -->
   677 		</form>
   723 		</form>
   678 	<?php endif; ?>
   724 	<?php endif; ?>
   679 	</div><!-- /manage-menus -->
   725 	</div><!-- /manage-menus -->
   680 	<div id="nav-menus-frame">
   726 	<div id="nav-menus-frame" class="wp-clearfix">
   681 	<div id="menu-settings-column" class="metabox-holder<?php if ( isset( $_GET['menu'] ) && '0' == $_GET['menu'] ) { echo ' metabox-holder-disabled'; } ?>">
   727 	<div id="menu-settings-column" class="metabox-holder<?php if ( isset( $_GET['menu'] ) && '0' == $_GET['menu'] ) { echo ' metabox-holder-disabled'; } ?>">
   682 
   728 
   683 		<div class="clear"></div>
   729 		<div class="clear"></div>
   684 
   730 
   685 		<form id="nav-menu-meta" class="nav-menu-meta" method="post" enctype="multipart/form-data">
   731 		<form id="nav-menu-meta" class="nav-menu-meta" method="post" enctype="multipart/form-data">
   692 	</div><!-- /#menu-settings-column -->
   738 	</div><!-- /#menu-settings-column -->
   693 	<div id="menu-management-liquid">
   739 	<div id="menu-management-liquid">
   694 		<div id="menu-management">
   740 		<div id="menu-management">
   695 			<form id="update-nav-menu" method="post" enctype="multipart/form-data">
   741 			<form id="update-nav-menu" method="post" enctype="multipart/form-data">
   696 				<div class="menu-edit <?php if ( $add_new_screen ) echo 'blank-slate'; ?>">
   742 				<div class="menu-edit <?php if ( $add_new_screen ) echo 'blank-slate'; ?>">
       
   743 					<input type="hidden" name="nav-menu-data">
   697 					<?php
   744 					<?php
   698 					wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
   745 					wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
   699 					wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
   746 					wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
   700 					wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' );
   747 					wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' );
   701 
   748 
   702 					if ( $one_theme_location_no_menus ) { ?>
   749 					$menu_name_aria_desc = $add_new_screen ? ' aria-describedby="menu-name-desc"' : '';
       
   750 
       
   751 					if ( $one_theme_location_no_menus ) {
       
   752 						$menu_name_val = 'value="' . esc_attr( 'Menu 1' ) . '"';
       
   753 					?>
   703 						<input type="hidden" name="zero-menu-state" value="true" />
   754 						<input type="hidden" name="zero-menu-state" value="true" />
   704 					<?php } ?>
   755 					<?php } else {
       
   756 						$menu_name_val = 'value="' . esc_attr( $nav_menu_selected_title ) . '"';
       
   757 					} ?>
   705  					<input type="hidden" name="action" value="update" />
   758  					<input type="hidden" name="action" value="update" />
   706 					<input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
   759 					<input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
   707 					<div id="nav-menu-header">
   760 					<div id="nav-menu-header">
   708 						<div class="major-publishing-actions">
   761 						<div class="major-publishing-actions wp-clearfix">
   709 							<label class="menu-name-label howto open-label" for="menu-name">
   762 							<label class="menu-name-label" for="menu-name"><?php _e( 'Menu Name' ); ?></label>
   710 								<span><?php _e( 'Menu Name' ); ?></span>
   763 							<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; ?> />
   711 								<input name="menu-name" id="menu-name" type="text" class="menu-name regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e( 'Enter menu name here' ); ?>" value="<?php if ( $one_theme_location_no_menus ) _e( 'Menu 1' ); else echo esc_attr( $nav_menu_selected_title ); ?>" />
       
   712 							</label>
       
   713 							<div class="publishing-action">
   764 							<div class="publishing-action">
   714 								<?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'button-primary menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?>
   765 								<?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?>
   715 							</div><!-- END .publishing-action -->
   766 							</div><!-- END .publishing-action -->
   716 						</div><!-- END .major-publishing-actions -->
   767 						</div><!-- END .major-publishing-actions -->
   717 					</div><!-- END .nav-menu-header -->
   768 					</div><!-- END .nav-menu-header -->
   718 					<div id="post-body">
   769 					<div id="post-body">
   719 						<div id="post-body-content">
   770 						<div id="post-body-content" class="wp-clearfix">
   720 							<?php if ( ! $add_new_screen ) : ?>
   771 							<?php if ( ! $add_new_screen ) : ?>
   721 							<h3><?php _e( 'Menu Structure' ); ?></h3>
   772 							<h3><?php _e( 'Menu Structure' ); ?></h3>
   722 							<?php $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.' ); ?>
   773 							<?php $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.' ); ?>
   723 							<div class="drag-instructions post-body-plain" <?php if ( isset( $menu_items ) && 0 == count( $menu_items ) ) { ?>style="display: none;"<?php } ?>>
   774 							<div class="drag-instructions post-body-plain" <?php if ( isset( $menu_items ) && 0 == count( $menu_items ) ) { ?>style="display: none;"<?php } ?>>
   724 								<p><?php echo $starter_copy; ?></p>
   775 								<p><?php echo $starter_copy; ?></p>
   730 							?>
   781 							?>
   731 							<ul class="menu" id="menu-to-edit"></ul>
   782 							<ul class="menu" id="menu-to-edit"></ul>
   732 							<?php } ?>
   783 							<?php } ?>
   733 							<?php endif; ?>
   784 							<?php endif; ?>
   734 							<?php if ( $add_new_screen ) : ?>
   785 							<?php if ( $add_new_screen ) : ?>
   735 								<p class="post-body-plain"><?php _e( 'Give your menu a name above, then click Create Menu.' ); ?></p>
   786 								<p class="post-body-plain" id="menu-name-desc"><?php _e( 'Give your menu a name, then click Create Menu.' ); ?></p>
   736 								<?php if ( isset( $_GET['use-location'] ) ) : ?>
   787 								<?php if ( isset( $_GET['use-location'] ) ) : ?>
   737 									<input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" />
   788 									<input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" />
   738 								<?php endif; ?>
   789 								<?php endif; ?>
   739 							<?php endif; ?>
   790 							<?php endif; ?>
   740 							<div class="menu-settings" <?php if ( $one_theme_location_no_menus ) { ?>style="display: none;"<?php } ?>>
   791 							<div class="menu-settings" <?php if ( $one_theme_location_no_menus ) { ?>style="display: none;"<?php } ?>>
   748 										$auto_add = true;
   799 										$auto_add = true;
   749 									else
   800 									else
   750 										$auto_add = false;
   801 										$auto_add = false;
   751 								} ?>
   802 								} ?>
   752 
   803 
   753 								<dl class="auto-add-pages">
   804 								<fieldset class="menu-settings-group auto-add-pages">
   754 									<dt class="howto"><?php _e( 'Auto add pages' ); ?></dt>
   805 									<legend class="menu-settings-group-name howto"><?php _e( 'Auto add pages' ); ?></legend>
   755 									<dd class="checkbox-input"><input type="checkbox"<?php checked( $auto_add ); ?> name="auto-add-pages" id="auto-add-pages" value="1" /> <label for="auto-add-pages"><?php printf( __('Automatically add new top-level pages to this menu' ), esc_url( admin_url( 'edit.php?post_type=page' ) ) ); ?></label></dd>
   806 									<div class="menu-settings-input checkbox-input">
   756 								</dl>
   807 										<input type="checkbox"<?php checked( $auto_add ); ?> name="auto-add-pages" id="auto-add-pages" value="1" /> <label for="auto-add-pages"><?php printf( __('Automatically add new top-level pages to this menu' ), esc_url( admin_url( 'edit.php?post_type=page' ) ) ); ?></label>
       
   808 									</div>
       
   809 								</fieldset>
   757 
   810 
   758 								<?php if ( current_theme_supports( 'menus' ) ) : ?>
   811 								<?php if ( current_theme_supports( 'menus' ) ) : ?>
   759 
   812 
   760 									<dl class="menu-theme-locations">
   813 									<fieldset class="menu-settings-group menu-theme-locations">
   761 										<dt class="howto"><?php _e( 'Theme locations' ); ?></dt>
   814 										<legend class="menu-settings-group-name howto"><?php _e( 'Display location' ); ?></legend>
   762 										<?php foreach ( $locations as $location => $description ) : ?>
   815 										<?php foreach ( $locations as $location => $description ) : ?>
   763 										<dd class="checkbox-input">
   816 										<div class="menu-settings-input checkbox-input">
   764 											<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 ); ?>" /> <label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label>
   817 											<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 ); ?>" />
       
   818 											<label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label>
   765 											<?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] != $nav_menu_selected_id ) : ?>
   819 											<?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] != $nav_menu_selected_id ) : ?>
   766 											<span class="theme-location-set"> <?php printf( __( "(Currently set to: %s)" ), wp_get_nav_menu_object( $menu_locations[ $location ] )->name ); ?> </span>
   820 												<span class="theme-location-set"><?php
       
   821 													/* translators: %s: menu name */
       
   822 													printf( _x( '(Currently set to: %s)', 'menu location' ),
       
   823 														wp_get_nav_menu_object( $menu_locations[ $location ] )->name
       
   824 													);
       
   825 												?></span>
   767 											<?php endif; ?>
   826 											<?php endif; ?>
   768 										</dd>
   827 										</div>
   769 										<?php endforeach; ?>
   828 										<?php endforeach; ?>
   770 									</dl>
   829 									</fieldset>
   771 
   830 
   772 								<?php endif; ?>
   831 								<?php endif; ?>
   773 
   832 
   774 							</div>
   833 							</div>
   775 						</div><!-- /#post-body-content -->
   834 						</div><!-- /#post-body-content -->
   776 					</div><!-- /#post-body -->
   835 					</div><!-- /#post-body -->
   777 					<div id="nav-menu-footer">
   836 					<div id="nav-menu-footer">
   778 						<div class="major-publishing-actions">
   837 						<div class="major-publishing-actions wp-clearfix">
   779 							<?php if ( 0 != $menu_count && ! $add_new_screen ) : ?>
   838 							<?php if ( 0 != $menu_count && ! $add_new_screen ) : ?>
   780 							<span class="delete-action">
   839 							<span class="delete-action">
   781 								<a class="submitdelete deletion menu-delete" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'menu' => $nav_menu_selected_id, admin_url() ) ), 'delete-nav_menu-' . $nav_menu_selected_id) ); ?>"><?php _e('Delete Menu'); ?></a>
   840 								<a class="submitdelete deletion menu-delete" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'menu' => $nav_menu_selected_id ), admin_url( 'nav-menus.php' ) ), 'delete-nav_menu-' . $nav_menu_selected_id) ); ?>"><?php _e('Delete Menu'); ?></a>
   782 							</span><!-- END .delete-action -->
   841 							</span><!-- END .delete-action -->
   783 							<?php endif; ?>
   842 							<?php endif; ?>
   784 							<div class="publishing-action">
   843 							<div class="publishing-action">
   785 								<?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'button-primary menu-save', 'save_menu', false, array( 'id' => 'save_menu_footer' ) ); ?>
   844 								<?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'primary large menu-save', 'save_menu', false, array( 'id' => 'save_menu_footer' ) ); ?>
   786 							</div><!-- END .publishing-action -->
   845 							</div><!-- END .publishing-action -->
   787 						</div><!-- END .major-publishing-actions -->
   846 						</div><!-- END .major-publishing-actions -->
   788 					</div><!-- /#nav-menu-footer -->
   847 					</div><!-- /#nav-menu-footer -->
   789 				</div><!-- /.menu-edit -->
   848 				</div><!-- /.menu-edit -->
   790 			</form><!-- /#update-nav-menu -->
   849 			</form><!-- /#update-nav-menu -->