Make WordPress Core


Ignore:
Timestamp:
05/14/2010 06:20:30 AM (14 years ago)
Author:
nacin
Message:

First pass on 'Theme Locations' for navigation menus. Themes need to specify a location when calling wp_nav_menu and register locations in functions.php. Users then map menus to locations in the nav menu admin. Subject to review. see #13378.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/nav-menu.php

    r14614 r14620  
    309309function wp_nav_menu_setup() {
    310310    // Register meta boxes
     311    add_meta_box( 'nav-menu-theme-locations', __( 'Theme Locations' ), 'wp_nav_menu_locations_meta_box' , 'nav-menus', 'side', 'default' );
    311312    add_meta_box( 'add-custom-links', __('Custom Links'), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
    312313    wp_nav_menu_post_type_meta_boxes();
     
    338339        return;
    339340
    340     $initial_meta_boxes = array( 'manage-menu', 'create-menu', 'add-custom-links', 'add-page', 'add-category' );
     341    $initial_meta_boxes = array( 'nav-menu-theme-locations', 'add-custom-links', 'add-page', 'add-category' );
    341342    $hidden_meta_boxes = array();
    342343
     
    395396        }
    396397    }
     398}
     399
     400/**
     401 * Displays a metabox for the nav menu theme locations.
     402 *
     403 * @since 3.0.0
     404 */
     405function wp_nav_menu_locations_meta_box() {
     406    $locations = get_registered_nav_menus();
     407    $mods = get_nav_menu_locations();
     408    $menus = wp_get_nav_menus();
     409    $menu_locations = get_nav_menu_locations();
     410    //var_dump( $menus );
     411    foreach ( $locations as $location => $description ) {
     412        ?>
     413        <p>
     414            <label class="howto" for="locations-<?php echo $location; ?>">
     415                <span><?php echo $description; ?></span>
     416                <select name="menu-locations[<?php echo $location; ?>]" id="locations-<?php echo $location; ?>">
     417                    <option value=""></option>
     418                    <?php foreach ( $menus as $menu ) : ?>
     419                    <option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?>
     420                        value="<?php echo $menu->term_id; ?>"><?php echo $menu->name; ?></option>
     421                    <?php endforeach; ?>
     422                </select>
     423            </label>
     424        </p>
     425    <?php
     426    }
     427    ?>
     428    <p class="button-controls">
     429        <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
     430        <input type="submit" class="button-primary" name="nav-menu-locations" value="<?php esc_attr_e( 'Save' ); ?>" />
     431    </p>
     432    <?php
    397433}
    398434
Note: See TracChangeset for help on using the changeset viewer.