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/theme.php

    r41193 r41205  
    28172817    }
    28182818
     2819    /*
     2820     * Note that settings must be previewed even outside the customizer preview
     2821     * and also in the customizer pane itself. This is to enable loading an existing
     2822     * changeset into the customizer. Previewing the settings only has to be prevented
     2823     * here in the case of a customize_save action because this will cause WP to think
     2824     * there is nothing changed that needs to be saved.
     2825     */
     2826    $is_customize_save_action = (
     2827        wp_doing_ajax()
     2828        &&
     2829        isset( $_REQUEST['action'] )
     2830        &&
     2831        'customize_save' === wp_unslash( $_REQUEST['action'] )
     2832    );
     2833    $settings_previewed = ! $is_customize_save_action;
     2834
    28192835    require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    2820     $GLOBALS['wp_customize'] = new WP_Customize_Manager( compact( 'changeset_uuid', 'theme', 'messenger_channel' ) );
     2836    $GLOBALS['wp_customize'] = new WP_Customize_Manager( compact( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed' ) );
    28212837}
    28222838
     
    28502866    if ( empty( $wp_customize ) ) {
    28512867        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    2852         $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $changeset_post->post_name ) );
     2868        $wp_customize = new WP_Customize_Manager( array(
     2869            'changeset_uuid' => $changeset_post->post_name,
     2870            'settings_previewed' => false,
     2871        ) );
    28532872    }
    28542873
Note: See TracChangeset for help on using the changeset viewer.