Make WordPress Core

Ticket #42121: 42121.2.diff

File 42121.2.diff, 2.7 KB (added by obenland, 8 years ago)
  • src/wp-includes/class-wp-customize-nav-menus.php

     
    597597                // Attempt to re-map the nav menu location assignments when previewing a theme switch.
    598598                $mapped_nav_menu_locations = array();
    599599                if ( ! $this->manager->is_theme_active() ) {
    600                         $mapped_nav_menu_locations = wp_map_nav_menu_locations( get_nav_menu_locations(), $this->original_nav_menu_locations );
     600                        $theme_mods = get_option( 'theme_mods_' . $this->manager->get_stylesheet(), array() );
     601
     602                        // If there is no data from a previous activation, start fresh.
     603                        if ( empty( $theme_mods['nav_menu_locations'] ) ) {
     604                                $theme_mods['nav_menu_locations'] = array();
     605                        }
     606
     607                        $mapped_nav_menu_locations = wp_map_nav_menu_locations( $theme_mods['nav_menu_locations'], $this->original_nav_menu_locations );
    601608                }
    602609
    603610                foreach ( $locations as $location => $description ) {
  • src/wp-includes/nav-menu.php

     
    10841084 * @return array Nav menus mapped to new nav menu locations.
    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.
    10901091        if ( empty( $old_nav_menu_locations ) ) {
  • tests/phpunit/tests/menu/nav-menu.php

     
    4747                $this->assertEquals( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations );
    4848        }
    4949
     50
     51        function test_filter_registered_locations() {
     52                $this->register_nav_menu_locations( array( 'primary', 'secondary' ) );
     53                $old_next_theme_nav_menu_locations = $prev_theme_nav_menu_locations = array(
     54                        'primary' => 1,
     55                        'secondary' => 2,
     56                        'social' => 3,
     57                );
     58                $new_next_theme_nav_menu_locations = wp_map_nav_menu_locations( $old_next_theme_nav_menu_locations, $prev_theme_nav_menu_locations );
     59
     60                $expected_nav_menu_locations = array(
     61                        'primary' => 1,
     62                        'secondary' => 2,
     63                );
     64                $this->assertEquals( $expected_nav_menu_locations, $new_next_theme_nav_menu_locations );
     65        }
     66
    5067        /**
    5168         * Locations with the same name should map, switching to a theme not previously-active.
    5269         *