WordPress.org

Make WordPress Core

Changeset 15100


Ignore:
Timestamp:
06/02/10 05:10:31 (4 years ago)
Author:
nacin
Message:

Clear nav menu from menu locations on delete. Additional sanity checks. fixes #13690.

Location:
trunk/wp-admin
Files:
2 edited

Legend:

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

    r15077 r15100  
    474474                <span><?php echo $description; ?></span> 
    475475                <select name="menu-locations[<?php echo $location; ?>]" id="locations-<?php echo $location; ?>"> 
    476                     <option value=""></option> 
     476                    <option value="0"></option> 
    477477                    <?php foreach ( $menus as $menu ) : ?> 
    478478                    <option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?> 
  • trunk/wp-admin/nav-menus.php

    r15095 r15100  
    5656        check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' ); 
    5757        if ( isset( $_REQUEST['nav-menu-locations'] ) ) 
    58             set_theme_mod( 'nav_menu_locations', $_REQUEST['menu-locations'] ); 
     58            set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) ); 
    5959        elseif ( isset( $_REQUEST['menu-item'] ) ) 
    6060            wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] ); 
     
    234234 
    235235 
    236         if ( is_nav_menu_item( $menu_item_id ) ) { 
    237             if ( wp_delete_post( $menu_item_id, true ) ) { 
    238  
    239                 $messages[] = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>'; 
    240             } 
    241         } 
     236        if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) 
     237            $messages[] = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>'; 
    242238        break; 
    243239    case 'delete': 
     
    251247                $messages[] = '<div id="message" class="error"><p>' . $delete_nav_menu->get_error_message() . '</p></div>'; 
    252248            } else { 
     249                // Remove this menu from any locations. 
     250                $locations = get_theme_mod( 'nav_menu_locations' ); 
     251                foreach ( $locations as $location => $menu_id ) { 
     252                    if ( $menu_id == $nav_menu_selected_id ) 
     253                        $locations[ $location ] = 0; 
     254                } 
     255                set_theme_mod( 'nav_menu_locations', $locations ); 
    253256                $messages[] = '<div id="message" class="updated"><p>' . __('The menu has been successfully deleted.') . '</p></div>'; 
    254257                // Select the next available menu 
     
    276279        // Update menu theme locations 
    277280        if ( isset( $_POST['menu-locations'] ) ) 
    278             set_theme_mod( 'nav_menu_locations', $_POST['menu-locations'] ); 
     281            set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) ); 
    279282 
    280283        // Add Menu 
Note: See TracChangeset for help on using the changeset viewer.