3 * WordPress Administration for Navigation Menus
9 * @subpackage Administration
12 /** Load WordPress Administration Bootstrap */
13 require_once( './admin.php' );
15 // Load all the nav menu interface functions
16 require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
18 if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) )
19 wp_die( __( 'Your theme does not support navigation menus or widgets.' ) );
22 if ( ! current_user_can('edit_theme_options') )
23 wp_die( __( 'Cheatin’ uh?' ) );
25 wp_enqueue_script( 'nav-menu' );
28 wp_enqueue_script( 'jquery-touch-punch' );
30 // Container for any messages displayed to the user
33 // Container that stores the name of the active menu
34 $nav_menu_selected_title = '';
36 // The menu id of the current menu being edited
37 $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
39 // Get existing menu locations assignments
40 $locations = get_registered_nav_menus();
41 $menu_locations = get_nav_menu_locations();
42 $num_locations = count( array_keys( $locations ) );
44 // Allowed actions: add, update, delete
45 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
49 check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
50 if ( isset( $_REQUEST['nav-menu-locations'] ) )
51 set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) );
52 elseif ( isset( $_REQUEST['menu-item'] ) )
53 wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] );
55 case 'move-down-menu-item' :
56 // moving down a menu item is the same as moving up the next in order
57 check_admin_referer( 'move-menu_item' );
58 $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
59 if ( is_nav_menu_item( $menu_item_id ) ) {
60 $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
61 if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
62 $menu_id = (int) $menus[0];
63 $ordered_menu_items = wp_get_nav_menu_items( $menu_id );
64 $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
66 // set up the data we need in one pass through the array of menu items
67 $dbids_to_orders = array();
68 $orders_to_dbids = array();
69 foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
70 if ( isset( $ordered_menu_item_object->ID ) ) {
71 if ( isset( $ordered_menu_item_object->menu_order ) ) {
72 $dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
73 $orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
80 isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1] )
82 $next_item_id = $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1];
83 $next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) );
85 // if not siblings of same parent, bubble menu item up but keep order
87 ! empty( $menu_item_data['menu_item_parent'] ) &&
89 empty( $next_item_data['menu_item_parent'] ) ||
90 $next_item_data['menu_item_parent'] != $menu_item_data['menu_item_parent']
94 $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
96 $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
98 if ( ! is_wp_error( $parent_object ) ) {
99 $parent_data = (array) $parent_object;
100 $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
101 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
105 // make menu item a child of its next sibling
107 $next_item_data['menu_order'] = $next_item_data['menu_order'] - 1;
108 $menu_item_data['menu_order'] = $menu_item_data['menu_order'] + 1;
110 $menu_item_data['menu_item_parent'] = $next_item_data['ID'];
111 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
113 wp_update_post($menu_item_data);
114 wp_update_post($next_item_data);
117 // the item is last but still has a parent, so bubble up
119 ! empty( $menu_item_data['menu_item_parent'] ) &&
120 in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids )
122 $menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true);
123 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
129 case 'move-up-menu-item' :
130 check_admin_referer( 'move-menu_item' );
131 $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
132 if ( is_nav_menu_item( $menu_item_id ) ) {
133 $menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
134 if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
135 $menu_id = (int) $menus[0];
136 $ordered_menu_items = wp_get_nav_menu_items( $menu_id );
137 $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
139 // set up the data we need in one pass through the array of menu items
140 $dbids_to_orders = array();
141 $orders_to_dbids = array();
142 foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
143 if ( isset( $ordered_menu_item_object->ID ) ) {
144 if ( isset( $ordered_menu_item_object->menu_order ) ) {
145 $dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
146 $orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
151 // if this menu item is not first
152 if ( ! empty( $dbids_to_orders[$menu_item_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) {
154 // if this menu item is a child of the previous
156 ! empty( $menu_item_data['menu_item_parent'] ) &&
157 in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) &&
158 isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) &&
159 ( $menu_item_data['menu_item_parent'] == $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] )
161 $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
162 $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
164 if ( ! is_wp_error( $parent_object ) ) {
165 $parent_data = (array) $parent_object;
167 // if there is something before the parent and parent a child of it, make menu item a child also of it
169 ! empty( $dbids_to_orders[$parent_db_id] ) &&
170 ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] ) &&
171 ! empty( $parent_data['menu_item_parent'] )
173 $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
175 // else if there is something before parent and parent not a child of it, make menu item a child of that something's parent
177 ! empty( $dbids_to_orders[$parent_db_id] ) &&
178 ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] )
180 $_possible_parent_id = (int) get_post_meta( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1], '_menu_item_menu_item_parent', true);
181 if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ) ) )
182 $menu_item_data['menu_item_parent'] = $_possible_parent_id;
184 $menu_item_data['menu_item_parent'] = 0;
186 // else there isn't something before the parent
188 $menu_item_data['menu_item_parent'] = 0;
191 // set former parent's [menu_order] to that of menu-item's
192 $parent_data['menu_order'] = $parent_data['menu_order'] + 1;
194 // set menu-item's [menu_order] to that of former parent
195 $menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1;
198 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
199 wp_update_post($menu_item_data);
200 wp_update_post($parent_data);
203 // else this menu item is not a child of the previous
205 empty( $menu_item_data['menu_order'] ) ||
206 empty( $menu_item_data['menu_item_parent'] ) ||
207 ! in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) ||
208 empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ||
209 $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] != $menu_item_data['menu_item_parent']
211 // just make it a child of the previous; keep the order
212 $menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1];
213 update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
214 wp_update_post($menu_item_data);
221 case 'delete-menu-item':
222 $menu_item_id = (int) $_REQUEST['menu-item'];
224 check_admin_referer( 'delete-menu_item_' . $menu_item_id );
226 if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) )
227 $messages[] = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>';
231 check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
232 if ( is_nav_menu( $nav_menu_selected_id ) ) {
233 $deletion = wp_delete_nav_menu( $nav_menu_selected_id );
235 // Reset the selected menu
236 $nav_menu_selected_id = 0;
237 unset( $_REQUEST['menu'] );
240 if ( ! isset( $deletion ) )
243 if ( is_wp_error( $deletion ) )
244 $messages[] = '<div id="message" class="error"><p>' . $deletion->get_error_message() . '</p></div>';
246 $messages[] = '<div id="message" class="updated"><p>' . __( 'The menu has been successfully deleted.' ) . '</p></div>';
250 check_admin_referer( 'nav_menus_bulk_actions' );
251 foreach ( $_REQUEST['delete_menus'] as $menu_id_to_delete ) {
252 if ( ! is_nav_menu( $menu_id_to_delete ) )
255 $deletion = wp_delete_nav_menu( $menu_id_to_delete );
256 if ( is_wp_error( $deletion ) ) {
257 $messages[] = '<div id="message" class="error"><p>' . $deletion->get_error_message() . '</p></div>';
258 $deletion_error = true;
262 if ( empty( $deletion_error ) )
263 $messages[] = '<div id="message" class="updated"><p>' . __( 'Selected menus have been successfully deleted.' ) . '</p></div>';
267 check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
269 // Remove menu locations that have been unchecked
270 foreach ( $locations as $location => $description ) {
271 if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) ) && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id )
272 unset( $menu_locations[ $location ] );
275 // Merge new and existing menu locations if any new ones are set
276 if ( isset( $_POST['menu-locations'] ) ) {
277 $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
278 $menu_locations = array_merge( $menu_locations, $new_menu_locations );
281 // Set menu locations
282 set_theme_mod( 'nav_menu_locations', $menu_locations );
285 if ( 0 == $nav_menu_selected_id ) {
286 $new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
288 if ( $new_menu_title ) {
289 $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => $new_menu_title) );
291 if ( is_wp_error( $_nav_menu_selected_id ) ) {
292 $messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
294 $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
295 $nav_menu_selected_id = $_nav_menu_selected_id;
296 $nav_menu_selected_title = $_menu_object->name;
297 if ( isset( $_REQUEST['menu-item'] ) )
298 wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) );
299 if ( isset( $_REQUEST['zero-menu-state'] ) ) {
300 // If there are menu items, add them
301 wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title );
302 // Auto-save nav_menu_locations
303 $locations = get_theme_mod( 'nav_menu_locations' );
304 foreach ( (array) $locations as $location => $menu_id ) {
305 $locations[ $location ] = $nav_menu_selected_id;
306 break; // There should only be 1
308 set_theme_mod( 'nav_menu_locations', $locations );
310 if ( isset( $_REQUEST['use-location'] ) ) {
311 $locations = get_theme_mod( 'nav_menu_locations' );
312 if ( isset( $locations[$_REQUEST['use-location']] ) )
313 $locations[$_REQUEST['use-location']] = $nav_menu_selected_id;
314 set_theme_mod( 'nav_menu_locations', $locations );
316 // $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%s</strong> has been created.' ), $nav_menu_selected_title ) . '</p></div>';
317 wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) );
321 $messages[] = '<div id="message" class="error"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
324 // Update existing menu
327 $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
329 $menu_title = trim( esc_html( $_POST['menu-name'] ) );
330 if ( ! $menu_title ) {
331 $messages[] = '<div id="message" class="error"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
332 $menu_title = $_menu_object->name;
335 if ( ! is_wp_error( $_menu_object ) ) {
336 $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) );
337 if ( is_wp_error( $_nav_menu_selected_id ) ) {
338 $_menu_object = $_nav_menu_selected_id;
339 $messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
341 $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
342 $nav_menu_selected_title = $_menu_object->name;
347 if ( ! is_wp_error( $_menu_object ) ) {
348 $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) );
353 if ( ! $num_locations ) {
354 wp_redirect( admin_url( 'nav-menus.php' ) );
358 add_filter( 'screen_options_show_screen', '__return_false' );
360 if ( isset( $_POST['menu-locations'] ) ) {
361 check_admin_referer( 'save-menu-locations' );
363 $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
364 $menu_locations = array_merge( $menu_locations, $new_menu_locations );
365 // Set menu locations
366 set_theme_mod( 'nav_menu_locations', $menu_locations );
368 $messages[] = '<div id="message" class="updated"><p>' . __( 'Menu locations updated.' ) . '</p></div>';
374 $nav_menus = wp_get_nav_menus( array('orderby' => 'name') );
375 $menu_count = count( $nav_menus );
377 // Are we on the add new screen?
378 $add_new_screen = ( isset( $_GET['menu'] ) && 0 == $_GET['menu'] ) ? true : false;
380 $locations_screen = ( isset( $_GET['action'] ) && 'locations' == $_GET['action'] ) ? true : false;
382 // If we have one theme location, and zero menus, we take them right into editing their first menu
383 $page_count = wp_count_posts( 'page' );
384 $one_theme_location_no_menus = ( 1 == count( get_registered_nav_menus() ) && ! $add_new_screen && empty( $nav_menus ) && ! empty( $page_count->publish ) ) ? true : false;
386 $nav_menus_l10n = array(
387 'oneThemeLocationNoMenus' => $one_theme_location_no_menus,
388 'moveUp' => __( 'Move up one' ),
389 'moveDown' => __( 'Move down one' ),
390 'moveToTop' => __( 'Move to the top' ),
391 /* translators: %s: previous item name */
392 'moveUnder' => __( 'Move under %s' ),
393 /* translators: %s: previous item name */
394 'moveOutFrom' => __( 'Move out from under %s' ),
395 /* translators: %s: previous item name */
396 'under' => __( 'Under %s' ),
397 /* translators: %s: previous item name */
398 'outFrom' => __( 'Out from under %s' ),
399 /* translators: 1: item name, 2: item position, 3: total number of items */
400 'menuFocus' => __( '%1$s. Menu item %2$d of %3$d.' ),
401 /* translators: 1: item name, 2: item position, 3: parent item name */
402 'subMenuFocus' => __( '%1$s. Sub item number %2$d under %3$s.' ),
404 wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n );
406 // Redirect to add screen if there are no menus and this users has either zero, or more than 1 theme locations
407 if ( 0 == $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus )
408 wp_redirect( admin_url( 'nav-menus.php?action=edit&menu=0' ) );
410 // Get recently edited nav menu
411 $recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) );
412 if ( empty( $recently_edited ) && is_nav_menu( $nav_menu_selected_id ) )
413 $recently_edited = $nav_menu_selected_id;
415 // Use $recently_edited if none are selected
416 if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) )
417 $nav_menu_selected_id = $recently_edited;
419 // On deletion of menu, if another menu exists, show it
420 if ( ! $add_new_screen && 0 < $menu_count && isset( $_GET['action'] ) && 'delete' == $_GET['action'] )
421 $nav_menu_selected_id = $nav_menus[0]->term_id;
423 // Set $nav_menu_selected_id to 0 if no menus
424 if ( $one_theme_location_no_menus ) {
425 $nav_menu_selected_id = 0;
426 } elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) {
427 // if we have no selection yet, and we have menus, set to the first one in the list
428 $nav_menu_selected_id = $nav_menus[0]->term_id;
431 // Update the user's setting
432 if ( $nav_menu_selected_id != $recently_edited && is_nav_menu( $nav_menu_selected_id ) )
433 update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id );
435 // If there's a menu, get its name.
436 if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
437 $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
438 $nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : '';
441 // Generate truncated menu names
442 foreach( (array) $nav_menus as $key => $_nav_menu ) {
443 $nav_menus[$key]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '…' );
446 // Retrieve menu locations
447 if ( current_theme_supports( 'menus' ) ) {
448 $locations = get_registered_nav_menus();
449 $menu_locations = get_nav_menu_locations();
452 // Ensure the user will be able to scroll horizontally
453 // by adding a class for the max menu depth.
454 global $_wp_nav_menu_max_depth;
455 $_wp_nav_menu_max_depth = 0;
457 // Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth
458 if ( is_nav_menu( $nav_menu_selected_id ) ) {
459 $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'post_status' => 'any' ) );
460 $edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id );
463 function wp_nav_menu_max_depth($classes) {
464 global $_wp_nav_menu_max_depth;
465 return "$classes menu-max-depth-$_wp_nav_menu_max_depth";
468 add_filter('admin_body_class', 'wp_nav_menu_max_depth');
471 wp_initial_nav_menu_meta_boxes();
473 if ( ! current_theme_supports( 'menus' ) && ! $num_locations )
474 $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 “Custom Menus” widget on the <a href="%s">Widgets</a> screen.' ), admin_url( 'widgets.php' ) ) . '</p></div>';
476 if ( ! $locations_screen ) : // Main tab
477 $overview = '<p>' . __( 'This screen is used for managing your custom navigation menus.' ) . '</p>';
478 $overview .= '<p>' . sprintf( __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a “Custom Menus” 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 Thirteen', 'Twenty Twelve' ) . '</p>';
479 $overview .= '<p>' . __( 'From this screen you can:' ) . '</p>';
480 $overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>';
481 $overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>';
483 get_current_screen()->add_help_tab( array(
485 'title' => __( 'Overview' ),
486 'content' => $overview
489 $menu_management = '<p>' . __( 'The menu management box at the top of the screen is used to control which menu is opened in the editor below.' ) . '</p>';
490 $menu_management .= '<ul><li>' . __( 'To edit an existing menu, <strong>choose a menu from the drop down and click Select</strong>' ) . '</li>';
491 $menu_management .= '<li>' . __( 'If you haven’t yet created any menus, <strong>click the ’create a new menu’ link</strong> to get started' ) . '</li></ul>';
492 $menu_management .= '<p>' . __( 'You can assign theme locations to individual menus by <strong>selecting the desired settings</strong> at the bottom of the menu editor. To assign menus to all theme locations at once, <strong>visit the Manage Locations tab</strong> at the top of the screen.' ) . '</p>';
494 get_current_screen()->add_help_tab( array(
495 'id' => 'menu-management',
496 'title' => __( 'Menu Management' ),
497 'content' => $menu_management
500 $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>';
501 $editing_menus .= '<p>' . __( '<strong>Clicking the title 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>';
502 $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>';
503 $editing_menus .= '<li>' . __( 'To add a custom link, <strong>expand the Links section, enter a URL and link text, and click Add to Menu</strong>' ) .'</li>';
504 $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>';
505 $editing_menus .= '<li>' . __( 'Delete a menu item by <strong>expanding it and clicking the Remove link</strong>' ) . '</li></ul>';
507 get_current_screen()->add_help_tab( array(
508 'id' => 'editing-menus',
509 'title' => __( 'Editing Menus' ),
510 'content' => $editing_menus
512 else : // Locations Tab
513 $locations_overview = '<p>' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '</p>';
514 $locations_overview .= '<ul><li>' . __( 'To assign menus to one or more theme locations, <strong>select a menu from each location’s drop down.</strong> When you’re finished, <strong>click Save Changes</strong>' ) . '</li>';
515 $locations_overview .= '<li>' . __( 'To edit a menu currently assigned to a theme location, <strong>click the adjacent ’Edit’ link</strong>' ) . '</li>';
516 $locations_overview .= '<li>' . __( 'To add a new menu instead of assigning an existing one, <strong>click the ’Use new menu’ link</strong>. Your new menu will be automatically assigned to that theme location' ) . '</li></ul>';
518 get_current_screen()->add_help_tab( array(
519 'id' => 'locations-overview',
520 'title' => __( 'Overview' ),
521 'content' => $locations_overview
525 get_current_screen()->set_help_sidebar(
526 '<p><strong>' . __('For more information:') . '</strong></p>' .
527 '<p>' . __('<a href="http://codex.wordpress.org/Appearance_Menus_Screen" target="_blank">Documentation on Menus</a>') . '</p>' .
528 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
531 // Get the admin header
532 require_once( './admin-header.php' );
535 <?php screen_icon(); ?>
536 <h2 class="nav-tab-wrapper">
537 <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>
538 <?php if ( $num_locations && $menu_count ) : ?>
539 <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>
543 foreach( $messages as $message ) :
544 echo $message . "\n";
548 if ( $locations_screen ) :
549 echo '<p>' . sprintf( _n( 'Your theme supports %s menu. Select which menu you would like to use below.', 'Your theme supports %s menus. Select a menu to use for each theme location below.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>';
551 <div id="menu-locations-wrap">
552 <form method="post" action="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>">
553 <table class="widefat fixed" cellspacing="0" id="menu-locations-table">
556 <th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th>
557 <th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th>
562 <th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th>
563 <th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th>
566 <tbody class="menu-locations">
567 <?php foreach ( $locations as $_location => $_name ) { ?>
568 <tr id="menu-locations-row">
569 <td class="menu-location-title"><strong><?php echo $_name; ?></strong></td>
570 <td class="menu-location-menus">
571 <select name="menu-locations[<?php echo $_location; ?>]" id="locations-<?php echo $_location; ?>">
572 <option value="0"><?php printf( '— %s —', esc_html__( 'Select a Menu' ) ); ?></option>
573 <?php foreach ( $nav_menus as $menu ) : ?>
574 <?php $selected = isset( $menu_locations[$_location] ) && $menu_locations[$_location] == $menu->term_id; ?>
575 <option <?php if ( $selected ) echo 'data-orig="true"'; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>">
576 <?php echo wp_html_excerpt( $menu->name, 40, '…' ); ?>
580 <div class="locations-row-links">
581 <?php if ( isset( $menu_locations[ $_location ] ) && 0 != $menu_locations[ $_location ] ) : ?>
582 <span class="locations-edit-menu-link">
583 <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => $menu_locations[$_location] ), admin_url( 'nav-menus.php' ) ) ); ?>">
584 <?php _ex( 'Edit', 'menu' ); ?>
588 <span class="locations-add-menu-link">
589 <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0, 'use-location' => $_location ), admin_url( 'nav-menus.php' ) ) ); ?>">
590 <?php _ex( 'Use new menu', 'menu' ); ?>
593 </div><!-- #locations-row-links -->
594 </td><!-- .menu-location-menus -->
595 </tr><!-- #menu-locations-row -->
596 <?php } // foreach ?>
599 <p class="button-controls"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p>
600 <?php wp_nonce_field( 'save-menu-locations' ); ?>
601 <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
603 </div><!-- #menu-locations-wrap -->
604 <?php do_action( 'after_menu_locations_table' ); ?>
606 <div class="manage-menus">
607 <?php if ( $menu_count < 2 ) : ?>
608 <span class="add-edit-menu-action">
609 <?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' ) ) ) ); ?>
610 </span><!-- /add-edit-menu-action -->
612 <form method="get" action="<?php echo admin_url( 'nav-menus.php' ); ?>">
613 <input type="hidden" name="action" value="edit" />
614 <label for="menu" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label>
615 <select name="menu" id="menu">
616 <?php if ( $add_new_screen ) : ?>
617 <option value="0" selected="selected"><?php _e( '-- Select --' ); ?></option>
619 <?php foreach( (array) $nav_menus as $_nav_menu ) : ?>
620 <option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>>
622 echo esc_html( $_nav_menu->truncated_name ) ;
624 if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) {
625 $locations_assigned_to_this_menu = array();
626 foreach ( array_keys( $menu_locations, $_nav_menu->term_id ) as $menu_location_key ) {
627 $locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
629 $assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) ) );
631 // Adds ellipses following the number of locations defined in $assigned_locations
632 printf( ' (%1$s%2$s)',
633 implode( ', ', $assigned_locations ),
634 count( $locations_assigned_to_this_menu ) > count( $assigned_locations ) ? ' …' : ''
641 <span class="submit-btn"><input type="submit" class="button-secondary" value="<?php _e( 'Select' ); ?>"></span>
642 <span class="add-new-menu-action">
643 <?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' ) ) ) ); ?>
644 </span><!-- /add-new-menu-action -->
647 </div><!-- /manage-menus -->
648 <div id="nav-menus-frame">
649 <div id="menu-settings-column" class="metabox-holder<?php if ( isset( $_GET['menu'] ) && '0' == $_GET['menu'] ) { echo ' metabox-holder-disabled'; } ?>">
651 <div class="clear"></div>
653 <form id="nav-menu-meta" action="" class="nav-menu-meta" method="post" enctype="multipart/form-data">
654 <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
655 <input type="hidden" name="action" value="add-menu-item" />
656 <?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?>
657 <?php do_accordion_sections( 'nav-menus', 'side', null ); ?>
660 </div><!-- /#menu-settings-column -->
661 <div id="menu-management-liquid">
662 <div id="menu-management">
663 <form id="update-nav-menu" action="" method="post" enctype="multipart/form-data">
664 <div class="menu-edit <?php if ( $add_new_screen ) echo 'blank-slate'; ?>">
666 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
667 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
668 wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' );
670 if ( $one_theme_location_no_menus ) { ?>
671 <input type="hidden" name="zero-menu-state" value="true" />
673 <input type="hidden" name="action" value="update" />
674 <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
675 <div id="nav-menu-header">
676 <div class="major-publishing-actions">
677 <label class="menu-name-label howto open-label" for="menu-name">
678 <span><?php _e( 'Menu Name' ); ?></span>
679 <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 ); ?>" />
681 <div class="publishing-action">
682 <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'button-primary menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?>
683 </div><!-- END .publishing-action -->
684 </div><!-- END .major-publishing-actions -->
685 </div><!-- END .nav-menu-header -->
687 <div id="post-body-content">
688 <?php if ( ! $add_new_screen ) : ?>
689 <h3><?php _e( 'Menu Structure' ); ?></h3>
690 <?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.' ); ?>
691 <div class="drag-instructions post-body-plain" <?php if ( isset( $menu_items ) && 0 == count( $menu_items ) ) { ?>style="display: none;"<?php } ?>>
692 <p><?php echo $starter_copy; ?></p>
695 if ( isset( $edit_markup ) && ! is_wp_error( $edit_markup ) ) {
699 <ul class="menu" id="menu-to-edit"></ul>
702 <?php if ( $add_new_screen ) : ?>
703 <p class="post-body-plain"><?php _e( 'Give your menu a name above, then click Create Menu.' ); ?></p>
704 <?php if ( isset( $_GET['use-location'] ) ) : ?>
705 <input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" />
708 <div class="menu-settings" <?php if ( $one_theme_location_no_menus ) { ?>style="display: none;"<?php } ?>>
709 <h3><?php _e( 'Menu Settings' ); ?></h3>
711 if ( ! isset( $auto_add ) ) {
712 $auto_add = get_option( 'nav_menu_options' );
713 if ( ! isset( $auto_add['auto_add'] ) )
715 elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'] ) )
721 <dl class="auto-add-pages">
722 <dt class="howto"><?php _e( 'Auto add pages' ); ?></dt>
723 <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>
726 <?php if ( current_theme_supports( 'menus' ) ) : ?>
728 <dl class="menu-theme-locations">
729 <dt class="howto"><?php _e( 'Theme locations' ); ?></dt>
730 <?php foreach ( $locations as $location => $description ) : ?>
731 <dd class="checkbox-input">
732 <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>
733 <?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] != $nav_menu_selected_id ) : ?>
734 <span class="theme-location-set"> <?php printf( __( "(Currently set to: %s)" ), wp_get_nav_menu_object( $menu_locations[ $location ] )->name ); ?> </span>
743 </div><!-- /#post-body-content -->
744 </div><!-- /#post-body -->
745 <div id="nav-menu-footer">
746 <div class="major-publishing-actions">
747 <?php if ( 0 != $menu_count && ! $add_new_screen ) : ?>
748 <span class="delete-action">
749 <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>
750 </span><!-- END .delete-action -->
752 <div class="publishing-action">
753 <?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'button-primary menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?>
754 </div><!-- END .publishing-action -->
755 </div><!-- END .major-publishing-actions -->
756 </div><!-- /#nav-menu-footer -->
757 </div><!-- /.menu-edit -->
758 </form><!-- /#update-nav-menu -->
759 </div><!-- /#menu-management -->
760 </div><!-- /#menu-management-liquid -->
761 </div><!-- /#nav-menus-frame -->
764 <?php include( './admin-footer.php' ); ?>