Menus: Limit mapping to registered locations

Weeds out orphaned locations, so their information will not continue to be mapped to future themes.

Fixes #42121.


git-svn-id: https://develop.svn.wordpress.org/trunk@41811 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Konstantin Obenland 2017-10-10 17:07:31 +00:00
parent 828dff99e9
commit b02beaf298
2 changed files with 23 additions and 1 deletions

View File

@ -1084,7 +1084,8 @@ function _wp_menus_changed() {
* @return array Nav menus mapped to new nav menu locations.
*/
function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locations ) {
$registered_nav_menus = get_registered_nav_menus();
$registered_nav_menus = get_registered_nav_menus();
$new_nav_menu_locations = array_intersect_key( $new_nav_menu_locations, $registered_nav_menus );
// Short-circuit if there are no old nav menu location assignments to map.
if ( empty( $old_nav_menu_locations ) ) {

View File

@ -47,6 +47,27 @@ class Tests_Nav_Menu_Theme_Change extends WP_UnitTestCase {
$this->assertEquals( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations );
}
/**
* Only registered locations should be mapped and returned.
*
* @covers wp_map_nav_menu_locations()
*/
function test_filter_registered_locations() {
$this->register_nav_menu_locations( array( 'primary', 'secondary' ) );
$old_next_theme_nav_menu_locations = $prev_theme_nav_menu_locations = array(
'primary' => 1,
'secondary' => 2,
'social' => 3,
);
$new_next_theme_nav_menu_locations = wp_map_nav_menu_locations( $old_next_theme_nav_menu_locations, $prev_theme_nav_menu_locations );
$expected_nav_menu_locations = array(
'primary' => 1,
'secondary' => 2,
);
$this->assertEquals( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations );
}
/**
* Locations with the same name should map, switching to a theme not previously-active.
*