From 905a612d88fd58d0e800459a2ab7cdd090fd177c Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sun, 30 Aug 2015 03:00:45 +0000 Subject: [PATCH] Switching themes: if the new theme doesn't have `nav_menu_locations` defined, but the old theme does, copy the old theme's `nav_menu_locations` into the new theme's theme mods. cc melchoyce Fixes #18588. git-svn-id: https://develop.svn.wordpress.org/trunk@33808 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/theme.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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() );