WordPress.org

Make WordPress Core

Changeset 41811


Ignore:
Timestamp:
10/10/17 17:07:31 (4 months ago)
Author:
obenland
Message:

Menus: Limit mapping to registered locations

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

Fixes #42121.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r41801 r41811  
    10851085 */ 
    10861086function wp_map_nav_menu_locations( $new_nav_menu_locations, $old_nav_menu_locations ) { 
    1087     $registered_nav_menus = get_registered_nav_menus(); 
     1087    $registered_nav_menus   = get_registered_nav_menus(); 
     1088    $new_nav_menu_locations = array_intersect_key( $new_nav_menu_locations, $registered_nav_menus ); 
    10881089 
    10891090    // Short-circuit if there are no old nav menu location assignments to map. 
  • trunk/tests/phpunit/tests/menu/nav-menu.php

    r41237 r41811  
    4949 
    5050    /** 
     51     * Only registered locations should be mapped and returned. 
     52     * 
     53     * @covers wp_map_nav_menu_locations() 
     54     */ 
     55    function test_filter_registered_locations() { 
     56        $this->register_nav_menu_locations( array( 'primary', 'secondary' ) ); 
     57        $old_next_theme_nav_menu_locations = $prev_theme_nav_menu_locations = array( 
     58            'primary' => 1, 
     59            'secondary' => 2, 
     60            'social' => 3, 
     61        ); 
     62        $new_next_theme_nav_menu_locations = wp_map_nav_menu_locations( $old_next_theme_nav_menu_locations, $prev_theme_nav_menu_locations ); 
     63 
     64        $expected_nav_menu_locations = array( 
     65            'primary' => 1, 
     66            'secondary' => 2, 
     67        ); 
     68        $this->assertEquals( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations ); 
     69    } 
     70 
     71    /** 
    5172     * Locations with the same name should map, switching to a theme not previously-active. 
    5273     * 
Note: See TracChangeset for help on using the changeset viewer.