WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/14/2014 10:45:40 PM (7 years ago)
Author:
nacin
Message:

Customizer: Properly handle widget settings when activating a previewed theme.

props westonruter, ocean90, gcorne.
fixes #27767.

File:
1 edited

Legend:

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

    r27879 r28124  
    753753 */
    754754function switch_theme( $stylesheet ) {
    755     global $wp_theme_directories, $sidebars_widgets;
    756 
    757     if ( is_array( $sidebars_widgets ) )
    758         set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) );
     755    global $wp_theme_directories, $wp_customize, $sidebars_widgets;
     756
     757    $_sidebars_widgets = null;
     758    if ( 'wp_ajax_customize_save' === current_action() ) {
     759        $_sidebars_widgets = $wp_customize->post_value( $wp_customize->get_setting( 'old_sidebars_widgets_data' ) );
     760    } elseif ( is_array( $sidebars_widgets ) ) {
     761        $_sidebars_widgets = $sidebars_widgets;
     762    }
     763
     764    if ( is_array( $_sidebars_widgets ) ) {
     765        set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $_sidebars_widgets ) );
     766    }
    759767
    760768    $old_theme  = wp_get_theme();
     
    783791    update_option( 'current_theme', $new_name );
    784792
     793    // Migrate from the old mods_{name} option to theme_mods_{slug}.
    785794    if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) {
    786795        $default_theme_mods = (array) get_option( 'mods_' . $new_name );
    787796        add_option( "theme_mods_$stylesheet", $default_theme_mods );
     797    } else {
     798        /*
     799         * Since retrieve_widgets() is called when initializing the customizer theme,
     800         * we need to to remove the theme mods to avoid overwriting changes made via
     801         * the widget customizer when accessing wp-admin/widgets.php.
     802         */
     803        if ( 'wp_ajax_customize_save' === current_action() ) {
     804            remove_theme_mod( 'sidebars_widgets' );
     805        }
    788806    }
    789807
     
    17921810        $old_theme = wp_get_theme( $stylesheet );
    17931811
     1812        // Prevent retrieve_widgets() from running since Customizer already called it up front
     1813        if ( get_option( 'theme_switched_via_customizer' ) ) {
     1814            remove_action( 'after_switch_theme', '_wp_sidebars_changed' );
     1815            update_option( 'theme_switched_via_customizer', false );
     1816        }
     1817
    17941818        if ( $old_theme->exists() ) {
    17951819            /**
Note: See TracChangeset for help on using the changeset viewer.