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:
parent
828dff99e9
commit
b02beaf298
|
@ -1085,6 +1085,7 @@ function _wp_menus_changed() {
|
|||
*/
|
||||
function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locations ) {
|
||||
$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 ) ) {
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue