diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index ae12810961..a9f0e6ed8d 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -688,6 +688,8 @@ function switch_theme( $stylesheet ) { set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $_sidebars_widgets ) ); } + $nav_menu_locations = get_theme_mod( 'nav_menu_locations' ); + $old_theme = wp_get_theme(); $new_theme = wp_get_theme( $stylesheet ); @@ -716,6 +718,9 @@ function switch_theme( $stylesheet ) { // Migrate from the old mods_{name} option to theme_mods_{slug}. if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) { $default_theme_mods = (array) get_option( 'mods_' . $new_name ); + if ( ! empty( $nav_menu_locations ) && empty( $default_theme_mods['nav_menu_locations'] ) ) { + $default_theme_mods['nav_menu_locations'] = $nav_menu_locations; + } add_option( "theme_mods_$stylesheet", $default_theme_mods ); } else { /* @@ -726,6 +731,13 @@ function switch_theme( $stylesheet ) { if ( 'wp_ajax_customize_save' === current_action() ) { remove_theme_mod( 'sidebars_widgets' ); } + + if ( ! empty( $nav_menu_locations ) ) { + $nav_mods = get_theme_mod( 'nav_menu_locations' ); + if ( empty( $nav_mods ) ) { + set_theme_mod( 'nav_menu_locations', $nav_menu_locations ); + } + } } update_option( 'theme_switched', $old_theme->get_stylesheet() );