Nav menus: Allow assigning a new menu to an existing location when no theme setting is currently saved.

props ocean90.
see #25064, for trunk.


git-svn-id: https://develop.svn.wordpress.org/trunk@25195 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2013-08-31 01:36:49 +00:00
parent 751fdfbc47
commit a86a9f671d
1 changed files with 7 additions and 6 deletions

View File

@ -300,18 +300,19 @@ switch ( $action ) {
// If there are menu items, add them // If there are menu items, add them
wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ); wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title );
// Auto-save nav_menu_locations // Auto-save nav_menu_locations
$locations = get_theme_mod( 'nav_menu_locations' ); $locations = get_nav_menu_locations();
foreach ( (array) $locations as $location => $menu_id ) { foreach ( $locations as $location => $menu_id ) {
$locations[ $location ] = $nav_menu_selected_id; $locations[ $location ] = $nav_menu_selected_id;
break; // There should only be 1 break; // There should only be 1
} }
set_theme_mod( 'nav_menu_locations', $locations ); set_theme_mod( 'nav_menu_locations', $locations );
} }
if ( isset( $_REQUEST['use-location'] ) ) { if ( isset( $_REQUEST['use-location'] ) ) {
$locations = get_theme_mod( 'nav_menu_locations' ); $locations = get_registered_nav_menus();
if ( isset( $locations[$_REQUEST['use-location']] ) ) $menu_locations = get_nav_menu_locations();
$locations[$_REQUEST['use-location']] = $nav_menu_selected_id; if ( isset( $locations[ $_REQUEST['use-location'] ] ) )
set_theme_mod( 'nav_menu_locations', $locations ); $menu_locations[ $_REQUEST['use-location'] ] = $nav_menu_selected_id;
set_theme_mod( 'nav_menu_locations', $menu_locations );
} }
// $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%s</strong> has been created.' ), $nav_menu_selected_title ) . '</p></div>'; // $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%s</strong> has been created.' ), $nav_menu_selected_title ) . '</p></div>';
wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) ); wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) );