WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/23/2010 10:06:21 PM (11 years ago)
Author:
ryan
Message:

Some nav menu API. see #11817

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/custom-navigation.php

    r13342 r13344  
    3030require_once (ABSPATH . WPINC . '/custom-navigation.php');
    3131
    32 function wp_custom_nav_reset() {
     32function wp_reset_nav_menu() {
    3333    wp_custom_navigation_setup(true);
    3434
     
    7878
    7979    if ( $insert_menu_name != '' ) {
    80         $existing_term = get_term_by( 'name', $insert_menu_name, 'nav_menu' );
    81         if ( $existing_term ) {
    82             $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . esc_html( sprintf( e__('A menu named "%s" already exists; please try another name.'), $existing_term->name ) ) . '</p></div>';
     80        $menu = wp_create_nav_menu($insert_menu_name);
     81        if ( is_wp_error($menu) ) {
     82            $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . esc_html( $menu->get_error_message() ) . '</p></div>';
    8383        } else {
    84             $term = wp_insert_term( $insert_menu_name, 'nav_menu' );
    85             if ( !is_wp_error($term) ) {
    86                 $term = get_term($term['term_id'], 'nav_menu');
    87                 $custom_menus[$term->term_id] = $term;
    88                 $menu_selected_id = $term->term_id;
    89                 $menu_id_in_edit = $menu_selected_id;
    90                 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . esc_html( sprintf( __('"%s" menu has been created!'), $term->name ) ) . '</p></div>';
    91 
    92                 $postCounter = 0;
    93             }
     84            $custom_menus[$menu->term_id] = $menu;
     85            $menu_selected_id = $menu->term_id;
     86            $menu_id_in_edit = $menu_selected_id;
     87            $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . esc_html( sprintf( __('"%s" menu has been created!'), $menu->name ) ) . '</p></div>';
     88            $postCounter = 0;
    9489        }
    9590    } else {
     
    9994
    10095if ( isset($_POST['reset_wp_menu']) ) {
    101     $success = wp_custom_nav_reset();
     96    $success = wp_reset_nav_menu();
    10297    if ( $success ) {
    10398        // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
     
    111106    }
    112107} elseif ( $postCounter > 0 && $menu_selected_id > 0 ) {
    113     $menu_objects = get_objects_in_term( $menu_selected_id, 'nav_menu' );
    114     $menu_items = wp_custom_navigation_get_menu_items( $menu_objects );
     108    $menu_items = wp_get_nav_menu_items( $menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
    115109
    116110    // Loop through all POST variables
Note: See TracChangeset for help on using the changeset viewer.