490 | | * Displays a metabox for the nav menu theme locations. |
491 | | * |
492 | | * @since 3.0.0 |
493 | | */ |
494 | | function wp_nav_menu_locations_meta_box() { |
495 | | global $nav_menu_selected_id; |
496 | | |
497 | | if ( ! current_theme_supports( 'menus' ) ) { |
498 | | // We must only support widgets. Leave a message and bail. |
499 | | echo '<p class="howto">' . __('The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.') . '</p>'; |
500 | | return; |
501 | | } |
502 | | |
503 | | $locations = get_registered_nav_menus(); |
504 | | $menus = wp_get_nav_menus(); |
505 | | $menu_locations = get_nav_menu_locations(); |
506 | | $num_locations = count( array_keys($locations) ); |
507 | | |
508 | | echo '<p class="howto">' . _n( 'Select a menu to use within your theme.', 'Select the menus you will use in your theme.', $num_locations ) . '</p>'; |
509 | | |
510 | | foreach ( $locations as $location => $description ) { |
511 | | ?> |
512 | | <p> |
513 | | <label class="howto" for="locations-<?php echo $location; ?>"> |
514 | | <span><?php echo $description; ?></span> |
515 | | <select name="menu-locations[<?php echo $location; ?>]" id="locations-<?php echo $location; ?>"> |
516 | | <option value="0"></option> |
517 | | <?php foreach ( $menus as $menu ) : ?> |
518 | | <option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?> |
519 | | value="<?php echo $menu->term_id; ?>"><?php echo wp_html_excerpt( $menu->name, 40, '…' ); ?></option> |
520 | | <?php endforeach; ?> |
521 | | </select> |
522 | | </label> |
523 | | </p> |
524 | | <?php |
525 | | } |
526 | | ?> |
527 | | <p class="button-controls"> |
528 | | <?php submit_button( __( 'Save' ), 'primary right', 'nav-menu-locations', false, wp_nav_menu_disabled_check( $nav_menu_selected_id ) ); ?> |
529 | | <span class="spinner"></span> |
530 | | </p> |
531 | | <?php |
532 | | } |
533 | | |
534 | | /** |