Make WordPress Core

Changeset 31705


Ignore:
Timestamp:
03/10/2015 10:38:30 PM (10 years ago)
Author:
ocean90
Message:

Customizer: Fix previewing and applying widgets when previewing another theme.

  • Unset wp_get_sidebars_widgets()' non-admin cache var $_wp_sidebars_widgets in Customize theme preview.
  • Add WP_Customize_Setting::$dirty so that settings can be initially-dirty when the Customizer loads.
  • Mark old_sidebars_widgets_data setting initially-dirty.
  • Mark all sidebars_widgets settings as initially-dirty during theme switch.

props westonruter.
see #31484.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/customize.php

    r31594 r31705  
    251251            'value'     => $setting->js_value(),
    252252            'transport' => $setting->transport,
     253            'dirty'     => $setting->dirty,
    253254        );
    254255    }
  • trunk/src/wp-admin/js/customize-controls.js

    r31704 r31705  
    1818            this.id = id;
    1919            this.transport = this.transport || 'refresh';
     20            this._dirty = options.dirty || false;
    2021
    2122            this.bind( this.preview );
     
    25172518            api.create( id, id, data.value, {
    25182519                transport: data.transport,
    2519                 previewer: api.previewer
     2520                previewer: api.previewer,
     2521                dirty: !! data.dirty
    25202522            } );
    25212523        });
  • trunk/src/wp-includes/class-wp-customize-setting.php

    r31543 r31705  
    6060    public $sanitize_callback    = '';
    6161    public $sanitize_js_callback = '';
     62
     63    /**
     64     * Whether or not the setting is initially dirty when created.
     65     *
     66     * This is used to ensure that a setting will be sent from the pane to the
     67     * preview when loading the Customizer. Normally a setting only is synced to
     68     * the preview if it has been changed. This allows the setting to be sent
     69     * from the start.
     70     *
     71     * @since 4.2.0
     72     * @access public
     73     * @var bool
     74     */
     75    public $dirty = false;
    6276
    6377    protected $id_data = array();
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r31544 r31705  
    217217        $sidebars_widgets = retrieve_widgets( 'customize' );
    218218        add_filter( 'option_sidebars_widgets', array( $this, 'filter_option_sidebars_widgets_for_theme_switch' ), 1 );
     219        unset( $GLOBALS['_wp_sidebars_widgets'] ); // reset global cache var used by wp_get_sidebars_widgets()
    219220    }
    220221
     
    333334            $setting_args = $this->get_setting_args( $setting_id, array(
    334335                'type' => 'global_variable',
     336                'dirty' => true,
    335337            ) );
    336338            $this->manager->add_setting( $setting_id, $setting_args );
     
    357359                $setting_args = $this->get_setting_args( $setting_id );
    358360                if ( ! $this->manager->get_setting( $setting_id ) ) {
     361                    if ( ! $this->manager->is_theme_active() ) {
     362                        $setting_args['dirty'] = true;
     363                    }
    359364                    $this->manager->add_setting( $setting_id, $setting_args );
    360365                }
  • trunk/tests/phpunit/tests/customize/setting.php

    r31622 r31705  
    4545        $this->assertFalse( has_filter( "customize_sanitize_{$setting->id}" ) );
    4646        $this->assertFalse( has_filter( "customize_sanitize_js_{$setting->id}" ) );
     47        $this->assertEquals( false, $setting->dirty );
    4748    }
    4849
Note: See TracChangeset for help on using the changeset viewer.