WordPress.org

Make WordPress Core

Changeset 13352


Ignore:
Timestamp:
02/23/2010 11:53:08 PM (12 years ago)
Author:
wpmuguru
Message:

add menu delete & other custom menu cleanup, See #11817

File:
1 edited

Legend:

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

    r13348 r13352  
    3838$messagesdiv = '';
    3939$menu_id_in_edit = 0;
     40$updated = false;
    4041
    4142// Check which menu is selected and if menu is in edit already
    42 if ( isset( $_POST['switch_menu'] ) )
     43if ( isset( $_POST['switch_menu'] ) ) {
    4344    $menu_selected_id = (int) $_POST['menu_select'];
    44 elseif ( isset( $_POST['menu_id_in_edit'] ) )
     45    $updated = true;
     46} elseif ( isset( $_POST['menu_id_in_edit'] ) ) {
    4547    $menu_selected_id = (int) $_POST['menu_id_in_edit'];
    46 else
     48} else {
    4749    $menu_selected_id = 0;
    48 
     50}
     51
     52if ( isset( $_POST[ 'delete_menu' ] ) && $menu_selected_id > 0 ) {
     53    wp_delete_nav_menu( $menu_selected_id );
     54    $menu_selected_id = 0;
     55    $updated = true;
     56}
    4957// Default Menu to show
    5058$custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
    51 if ( !empty( $custom_menus ) )
     59if ( ! $menu_selected_id && ! empty( $custom_menus ) )
    5260    $menu_selected_id = $custom_menus[0]->term_id;
    5361
     
    6573    // @todo validate set_wp_menu
    6674    update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] );
     75    $updated = true;
    6776    $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __('Menu has been updated!') . '</p></div>';
    6877}
     
    7483
    7584// Create a new menu. Menus are stored as terms in the 'menu' taxonomy.
    76 if ( isset( $_POST['add_menu'] ) ) {
     85if ( isset( $_POST['add_menu'] ) && ! $updated ) {
    7786    $insert_menu_name = $_POST['add_menu_name'];
    7887
     
    91100        $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . __('Please enter a valid menu name.') . '</p></div>';
    92101    }
    93 }
    94 
    95 if ( isset($_POST['reset_wp_menu']) ) {
     102    $updated = true;
     103}
     104
     105if ( isset($_POST['reset_wp_menu']) && ! $updated ) {
    96106    $success = wp_reset_nav_menu();
    97107    if ( $success ) {
     
    105115        $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . __('The menu could not be reset. Please try again.') . '</p></div>';
    106116    }
    107 } elseif ( $postCounter > 0 && $menu_selected_id > 0 ) {
     117} elseif ( $postCounter > 0 && $menu_selected_id > 0 && ! $updated ) {
    108118    $menu_items = wp_get_nav_menu_items( $menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
    109119    $parent_menu_ids = array();
     
    210220        </script>
    211221
     222        <input id="delete_menu" name="delete_menu" type="submit" value="<?php esc_attr_e('Delete This Menu'); ?>" />
    212223        <input id="save_bottom" name="save_bottom" type="submit" value="<?php esc_attr_e('Save All Changes'); ?>" /></p>
    213224        </div><!-- /.inside -->
Note: See TracChangeset for help on using the changeset viewer.