Map nav menu locations on theme switch

This will send nav menu locations through three levels of mapping:
1. If both themes have only one location, that gets mapped.
2. If both themes have locations with the same slug, they get mapped.
3. Locations that (even partially) match slugs from a similar kind of menu location will get mapped.

Menu locations are mapped for Live Previews in the Customizer and during theme switches.

Props westonruter, obenland, welcher, melchoyce.
Fixes #39692.



git-svn-id: https://develop.svn.wordpress.org/trunk@41237 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Konstantin Obenland
2017-08-09 21:03:16 +00:00
parent 9ab26b8800
commit d339af1bc1
5 changed files with 308 additions and 12 deletions

View File

@@ -691,6 +691,7 @@ function switch_theme( $stylesheet ) {
}
$nav_menu_locations = get_theme_mod( 'nav_menu_locations' );
add_option( 'theme_switch_menu_locations', $nav_menu_locations );
if ( func_num_args() > 1 ) {
$stylesheet = func_get_arg( 1 );
@@ -731,13 +732,6 @@ 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() );