WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/27/2010 11:06:56 PM (11 years ago)
Author:
wpmuguru
Message:

more menu improvements, props ptahdunbar, see #11817

File:
1 edited

Legend:

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

    r13407 r13473  
    88 */
    99
     10// Deletes a nav menu
    1011function wp_delete_nav_menu( $menu_id ) {
    1112    $menu_id = (int) $menu_id;
     
    2223}
    2324
     25// Creates a new nav menu
    2426function wp_create_nav_menu( $menu_name, $args = array() ) {
    2527    $menu_exists = get_term_by( 'name', $menu_name, 'nav_menu' );
    2628
    2729    if ( $menu_exists )
    28         return new WP_Error('menu_exists', sprintf( __('A menu named “%s” already exists; please try another name.'), esc_html( $menu_exists->name ) ) );
     30        return new WP_Error( 'menu_exists', sprintf( __('A menu named “%s” already exists; please try another name.'), esc_html( $menu_exists->name ) ) );
    2931
    3032    if ( isset($args['slug']) )
     
    4143}
    4244
     45// Creates a default menu if none exists
    4346function wp_create_default_nav_menu() {
    44     $menu = wp_create_nav_menu(__('Main'), array('slug' => 'main'));
     47    $menu = wp_create_nav_menu( __('Menu 1'), array('slug' => 'menu-1') );
    4548
    4649    if ( is_wp_error($menu) )
     
    5053    $counter = 1;
    5154    foreach ( $pages as $page ) {
    52         $item = array('post_status' => 'publish', 'post_type' => 'nav_menu_item', 'menu_order' => $counter, 'tax_input' => array( 'nav_menu' => $menu->name), 'post_title' => addslashes($page->post_title) );
     55        $item = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'menu_order' => $counter, 'tax_input' => array( 'nav_menu' => $menu->name), 'post_title' => addslashes($page->post_title) );
    5356        $item_id = wp_insert_post($item, true);
    5457        update_post_meta( $item_id, 'menu_type', 'page' );
     
    5962}
    6063
     64// Get nav menu by id
    6165function wp_get_nav_menu( $menu ) {
    62     return get_term( (int) $menu, 'nav_menu');
     66    return get_term( (int) $menu, 'nav_menu' );
    6367}
    6468
     69// Get all nav menus
    6570function wp_get_nav_menus() {
    6671    return get_terms( 'nav_menu', array( 'hide_empty' => false, 'orderby' => 'id' ) );
    6772}
    6873
     74// Get the nav menu items
    6975function wp_get_nav_menu_items( $menu, $args = array() ) {
    7076    $items = get_objects_in_term( (int) $menu, 'nav_menu' );
     
    9399}
    94100
     101// wp_setup_nav_menu_item()
    95102function wp_setup_nav_menu_item($menu_item, $type = 'item', $position = 0) {
    96103    global $parent_menu_order;
Note: See TracChangeset for help on using the changeset viewer.