Make WordPress Core


Ignore:
Timestamp:
08/02/2017 05:34:32 AM (7 years ago)
Author:
westonruter
Message:

Customize: Introduce settings_previewed arg and getter on WP_Customize_Manager which controls whether WP_Customize_Setting::preview() should be called on settings.

The settings_previewed property eliminates the need for the Customizer components from having to look at global doing_ajax state. This is in particular needed when saving settings, as some settings will short-circuit the update operation if they detect no changes are introduced. This is also needed for low-level integrations with the Customizer, such as in REST API endpoints under development.

Props stubgo, westonruter, utkarshpatel for testing.
See #38900.
Fixes #39221.

File:
1 edited

Legend:

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

    r41168 r41205  
    212212        $settings = $this->manager->add_dynamic_settings( array_unique( $widget_setting_ids ) );
    213213
    214         /*
    215          * Preview settings right away so that widgets and sidebars will get registered properly.
    216          * But don't do this if a customize_save because this will cause WP to think there is nothing
    217          * changed that needs to be saved.
    218          */
    219         if ( ! $this->manager->doing_ajax( 'customize_save' ) ) {
     214        if ( $this->manager->settings_previewed() ) {
    220215            foreach ( $settings as $setting ) {
    221216                $setting->preview();
     
    507502        }
    508503
    509         if ( ! $this->manager->doing_ajax( 'customize_save' ) ) {
     504        if ( $this->manager->settings_previewed() ) {
    510505            foreach ( $new_setting_ids as $new_setting_id ) {
    511506                $this->manager->get_setting( $new_setting_id )->preview();
Note: See TracChangeset for help on using the changeset viewer.