Make WordPress Core

Changeset 41995


Ignore:
Timestamp:
10/24/2017 06:34:21 PM (9 years ago)
Author:
obenland
Message:

Customize: Allow previewed menus to be customized

Fixes a bug where menu assignements couldn't be changed when previewing a theme.
Also removes an unnecessary call to menu mapping after a theme switch from the customizer and makes sure the locations option is always written, for good measure.

Props westonruter.
See #39692.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r41956 r41995  
    530530         */
    531531        public function customize_register() {
     532                $changeset = $this->manager->unsanitized_post_values();
    532533
    533534                // Preview settings for nav menus early so that the sections and controls will be added properly.
    534535                $nav_menus_setting_ids = array();
    535                 foreach ( array_keys( $this->manager->unsanitized_post_values() ) as $setting_id ) {
     536                foreach ( array_keys( $changeset ) as $setting_id ) {
    536537                        if ( preg_match( '/^(nav_menu_locations|nav_menu|nav_menu_item)\[/', $setting_id ) ) {
    537538                                $nav_menus_setting_ids[] = $setting_id;
     
    628629
    629630                        // Override the assigned nav menu location if mapped during previewed theme switch.
    630                         if ( isset( $mapped_nav_menu_locations[ $location ] ) ) {
     631                        if ( empty( $changeset[ $setting_id ] ) && isset( $mapped_nav_menu_locations[ $location ] ) ) {
    631632                                $this->manager->set_post_value( $setting_id, $mapped_nav_menu_locations[ $location ] );
    632633                        }
  • trunk/src/wp-includes/theme.php

    r41937 r41995  
    695695
    696696        $nav_menu_locations = get_theme_mod( 'nav_menu_locations' );
    697         add_option( 'theme_switch_menu_locations', $nav_menu_locations );
     697        update_option( 'theme_switch_menu_locations', $nav_menu_locations );
    698698
    699699        if ( func_num_args() > 1 ) {
     
    27252725                $old_theme = wp_get_theme( $stylesheet );
    27262726
    2727                 // Prevent retrieve_widgets() from running since Customizer already called it up front
     2727                // Prevent widget & menu mapping from running since Customizer already called it up front
    27282728                if ( get_option( 'theme_switched_via_customizer' ) ) {
     2729                        remove_action( 'after_switch_theme', '_wp_menus_changed' );
    27292730                        remove_action( 'after_switch_theme', '_wp_sidebars_changed' );
    27302731                        update_option( 'theme_switched_via_customizer', false );
Note: See TracChangeset for help on using the changeset viewer.