wp_die( __( 'Your theme does not support navigation menus or widgets.' ) );
// Permissions Check
-if ( ! current_user_can('edit_theme_options') )
- wp_die( __( 'Cheatin’ uh?' ), 403 );
+if ( ! current_user_can( 'edit_theme_options' ) ) {
+ wp_die(
+ '<h1>' . __( 'Cheatin’ uh?' ) . '</h1>' .
+ '<p>' . __( 'You are not allowed to edit theme options on this site.' ) . '</p>',
+ 403
+ );
+}
wp_enqueue_script( 'nav-menu' );
// Set up the data we need in one pass through the array of menu items.
$dbids_to_orders = array();
$orders_to_dbids = array();
- foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
+ foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
if ( isset( $ordered_menu_item_object->ID ) ) {
if ( isset( $ordered_menu_item_object->menu_order ) ) {
$dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
// Set up the data we need in one pass through the array of menu items.
$dbids_to_orders = array();
$orders_to_dbids = array();
- foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
+ foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) {
if ( isset( $ordered_menu_item_object->ID ) ) {
if ( isset( $ordered_menu_item_object->menu_order ) ) {
$dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
// Update menu items.
if ( ! is_wp_error( $_menu_object ) ) {
- $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) );
+ $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) );
+
+ // If the menu ID changed, redirect to the new URL.
+ if ( $nav_menu_selected_id != $_nav_menu_selected_id ) {
+ wp_redirect( admin_url( 'nav-menus.php?menu=' . intval( $_nav_menu_selected_id ) ) );
+ exit();
+ }
}
}
break;
}
// Generate truncated menu names.
-foreach( (array) $nav_menus as $key => $_nav_menu ) {
+foreach ( (array) $nav_menus as $key => $_nav_menu ) {
$nav_menus[$key]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '…' );
}
/*
* Ensure the user will be able to scroll horizontally
* by adding a class for the max menu depth.
+ *
+ * @global int $_wp_nav_menu_max_depth
*/
global $_wp_nav_menu_max_depth;
$_wp_nav_menu_max_depth = 0;
$edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id );
}
-function wp_nav_menu_max_depth($classes) {
+/**
+ *
+ * @global int $_wp_nav_menu_max_depth
+ *
+ * @param string $classes
+ * @return string
+ */
+function wp_nav_menu_max_depth( $classes ) {
global $_wp_nav_menu_max_depth;
return "$classes menu-max-depth-$_wp_nav_menu_max_depth";
}
require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>
<div class="wrap">
+ <h1><?php echo esc_html( __( 'Menus' ) ); ?>
+ <?php
+ if ( current_user_can( 'customize' ) ) :
+ $focus = $locations_screen ? array( 'section' => 'menu_locations' ) : array( 'panel' => 'nav_menus' );
+ printf(
+ ' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>',
+ esc_url( add_query_arg( array(
+ array( 'autofocus' => $focus ),
+ 'return' => urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
+ ), admin_url( 'customize.php' ) ) ),
+ __( 'Manage in Customizer' )
+ );
+ endif;
+ ?>
+ </h1>
<h2 class="nav-tab-wrapper">
<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>
<?php if ( $num_locations && $menu_count ) : ?>
<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>
- <?php endif; ?>
+ <?php
+ endif;
+ ?>
</h2>
<?php
- foreach( $messages as $message ) :
+ foreach ( $messages as $message ) :
echo $message . "\n";
endforeach;
?>
<?php else : ?>
<form method="get" action="<?php echo admin_url( 'nav-menus.php' ); ?>">
<input type="hidden" name="action" value="edit" />
- <label for="menu" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label>
- <select name="menu" id="menu">
+ <label for="select-menu-to-edit" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label>
+ <select name="menu" id="select-menu-to-edit">
<?php if ( $add_new_screen ) : ?>
<option value="0" selected="selected"><?php _e( '— Select —' ); ?></option>
<?php endif; ?>
- <?php foreach( (array) $nav_menus as $_nav_menu ) : ?>
+ <?php foreach ( (array) $nav_menus as $_nav_menu ) : ?>
<option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>>
<?php
echo esc_html( $_nav_menu->truncated_name ) ;
<dt class="howto"><?php _e( 'Theme locations' ); ?></dt>
<?php foreach ( $locations as $location => $description ) : ?>
<dd class="checkbox-input">
- <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>
+ <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>
<?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] != $nav_menu_selected_id ) : ?>
- <span class="theme-location-set"> <?php printf( __( "(Currently set to: %s)" ), wp_get_nav_menu_object( $menu_locations[ $location ] )->name ); ?> </span>
+ <span class="theme-location-set"><?php
+ /* translators: %s: menu name */
+ printf( _x( '(Currently set to: %s)', 'menu location' ),
+ wp_get_nav_menu_object( $menu_locations[ $location ] )->name
+ );
+ ?></span>
<?php endif; ?>
</dd>
<?php endforeach; ?>