<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[41205] trunk: Customize: Introduce `settings_previewed` arg and getter on `WP_Customize_Manager` which controls whether `WP_Customize_Setting::preview()` should be called on settings.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41205">41205</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41205","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-08-02 05:34:32 +0000 (Wed, 02 Aug 2017)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/38900">#38900</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/39221">#39221</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpcustomizemanagerphp">trunk/src/wp-includes/class-wp-customize-manager.php</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizenavmenusphp">trunk/src/wp-includes/class-wp-customize-nav-menus.php</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizewidgetsphp">trunk/src/wp-includes/class-wp-customize-widgets.php</a></li>
<li><a href="#trunksrcwpincludesthemephp">trunk/src/wp-includes/theme.php</a></li>
<li><a href="#trunktestsphpunittestscustomizemanagerphp">trunk/tests/phpunit/tests/customize/manager.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpcustomizemanagerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-customize-manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-manager.php 2017-08-02 05:10:05 UTC (rev 41204)
+++ trunk/src/wp-includes/class-wp-customize-manager.php 2017-08-02 05:34:32 UTC (rev 41205)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -174,6 +174,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> protected $messenger_channel;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Whether settings should be previewed.
+ *
+ * @since 4.9.0
+ * @var bool
+ */
+ protected $settings_previewed;
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Unsanitized values for Customize Settings parsed from $_POST['customized'].
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -213,15 +221,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $args {
</span><span class="cx" style="display: block; padding: 0 10px"> * Args.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type string $changeset_uuid Changeset UUID, the post_name for the customize_changeset post containing the customized state. Defaults to new UUID.
- * @type string $theme Theme to be previewed (for theme switch). Defaults to customize_theme or theme query params.
- * @type string $messenger_channel Messenger channel. Defaults to customize_messenger_channel query param.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type string $changeset_uuid Changeset UUID, the post_name for the customize_changeset post containing the customized state. Defaults to new UUID.
+ * @type string $theme Theme to be previewed (for theme switch). Defaults to customize_theme or theme query params.
+ * @type string $messenger_channel Messenger channel. Defaults to customize_messenger_channel query param.
+ * @type bool $settings_previewed If settings should be previewed. Defaults to true.
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function __construct( $args = array() ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $args = array_merge(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array_fill_keys( array( 'changeset_uuid', 'theme', 'messenger_channel' ), null ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ array_fill_keys( array( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed' ), null ),
</ins><span class="cx" style="display: block; padding: 0 10px"> $args
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -242,9 +251,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $args['messenger_channel'] = sanitize_key( wp_unslash( $_REQUEST['customize_messenger_channel'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! isset( $args['settings_previewed'] ) ) {
+ $args['settings_previewed'] = true;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->original_stylesheet = get_stylesheet();
</span><span class="cx" style="display: block; padding: 0 10px"> $this->theme = wp_get_theme( $args['theme'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->messenger_channel = $args['messenger_channel'];
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->settings_previewed = ! empty( $args['settings_previewed'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->_changeset_uuid = $args['changeset_uuid'];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> require_once( ABSPATH . WPINC . '/class-wp-customize-setting.php' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -622,6 +636,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Gets whether settings are or will be previewed.
+ *
+ * @since 4.9.0
+ * @see WP_Customize_Setting::preview()
+ *
+ * @return bool
+ */
+ public function settings_previewed() {
+ return $this->settings_previewed;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Get the changeset UUID.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.7.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -728,15 +754,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( 'customize_register', $this );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /*
- * Note that settings must be previewed here even outside the customizer preview
- * and also in the customizer pane itself. This is to enable loading an existing
- * changeset into the customizer. Previewing the settings only has to be prevented
- * in the case of a customize_save action because then update_option()
- * may short-circuit because it will detect that there are no changes to
- * make.
- */
- if ( ! $this->doing_ajax( 'customize_save' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $this->settings_previewed() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $this->settings as $setting ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $setting->preview();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizenavmenusphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-customize-nav-menus.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-nav-menus.php 2017-08-02 05:10:05 UTC (rev 41204)
+++ trunk/src/wp-includes/class-wp-customize-nav-menus.php 2017-08-02 05:34:32 UTC (rev 41205)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -526,13 +526,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $nav_menus_setting_ids[] = $setting_id;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->manager->add_dynamic_settings( $nav_menus_setting_ids );
- if ( ! $this->manager->doing_ajax( 'customize_save' ) ) {
- foreach ( $nav_menus_setting_ids as $setting_id ) {
- $setting = $this->manager->get_setting( $setting_id );
- if ( $setting ) {
- $setting->preview();
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $settings = $this->manager->add_dynamic_settings( $nav_menus_setting_ids );
+ if ( $this->manager->settings_previewed() ) {
+ foreach ( $settings as $setting ) {
+ $setting->preview();
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizewidgetsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-customize-widgets.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-widgets.php 2017-08-02 05:10:05 UTC (rev 41204)
+++ trunk/src/wp-includes/class-wp-customize-widgets.php 2017-08-02 05:34:32 UTC (rev 41205)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -211,12 +211,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $settings = $this->manager->add_dynamic_settings( array_unique( $widget_setting_ids ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /*
- * Preview settings right away so that widgets and sidebars will get registered properly.
- * But don't do this if a customize_save because this will cause WP to think there is nothing
- * changed that needs to be saved.
- */
- if ( ! $this->manager->doing_ajax( 'customize_save' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $this->manager->settings_previewed() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $settings as $setting ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $setting->preview();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -506,7 +501,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $this->manager->doing_ajax( 'customize_save' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $this->manager->settings_previewed() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $new_setting_ids as $new_setting_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->manager->get_setting( $new_setting_id )->preview();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/theme.php 2017-08-02 05:10:05 UTC (rev 41204)
+++ trunk/src/wp-includes/theme.php 2017-08-02 05:34:32 UTC (rev 41205)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2816,8 +2816,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $messenger_channel = sanitize_key( $input_vars['customize_messenger_channel'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Note that settings must be previewed even outside the customizer preview
+ * and also in the customizer pane itself. This is to enable loading an existing
+ * changeset into the customizer. Previewing the settings only has to be prevented
+ * here in the case of a customize_save action because this will cause WP to think
+ * there is nothing changed that needs to be saved.
+ */
+ $is_customize_save_action = (
+ wp_doing_ajax()
+ &&
+ isset( $_REQUEST['action'] )
+ &&
+ 'customize_save' === wp_unslash( $_REQUEST['action'] )
+ );
+ $settings_previewed = ! $is_customize_save_action;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $GLOBALS['wp_customize'] = new WP_Customize_Manager( compact( 'changeset_uuid', 'theme', 'messenger_channel' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $GLOBALS['wp_customize'] = new WP_Customize_Manager( compact( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2849,7 +2865,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $wp_customize ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $changeset_post->post_name ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $wp_customize = new WP_Customize_Manager( array(
+ 'changeset_uuid' => $changeset_post->post_name,
+ 'settings_previewed' => false,
+ ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! did_action( 'customize_register' ) ) {
</span></span></pre></div>
<a id="trunktestsphpunittestscustomizemanagerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/customize/manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/customize/manager.php 2017-08-02 05:10:05 UTC (rev 41204)
+++ trunk/tests/phpunit/tests/customize/manager.php 2017-08-02 05:34:32 UTC (rev 41205)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -216,6 +216,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Test WP_Customize_Manager::settings_previewed().
+ *
+ * @ticket 39221
+ * @covers WP_Customize_Manager::settings_previewed()
+ */
+ function test_settings_previewed() {
+ $wp_customize = new WP_Customize_Manager( array( 'settings_previewed' => false ) );
+ $this->assertSame( false, $wp_customize->settings_previewed() );
+
+ $wp_customize = new WP_Customize_Manager();
+ $this->assertSame( true, $wp_customize->settings_previewed() );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Test WP_Customize_Manager::changeset_uuid().
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 30937
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1292,6 +1306,54 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Test saving settings by publishing a changeset outside of Customizer entirely.
+ *
+ * Widgets get their settings registered and previewed early in the admin,
+ * so this ensures that the previewing is bypassed when in the context of
+ * publishing
+ *
+ * @ticket 39221
+ * @covers _wp_customize_publish_changeset()
+ * @see WP_Customize_Widgets::schedule_customize_register()
+ * @see WP_Customize_Widgets::customize_register()
+ */
+ function test_wp_customize_publish_changeset() {
+ global $wp_customize;
+ $wp_customize = null;
+
+ // Set the admin current screen to cause WP_Customize_Widgets::schedule_customize_register() to do early setting registration.
+ set_current_screen( 'edit' );
+ $this->assertTrue( is_admin() );
+
+ $old_sidebars_widgets = get_option( 'sidebars_widgets' );
+ $new_sidebars_widgets = $old_sidebars_widgets;
+ $this->assertGreaterThan( 2, count( $new_sidebars_widgets['sidebar-1'] ) );
+ $new_sidebar_1 = array_reverse( $new_sidebars_widgets['sidebar-1'] );
+
+ $post_id = $this->factory()->post->create( array(
+ 'post_type' => 'customize_changeset',
+ 'post_status' => 'draft',
+ 'post_name' => wp_generate_uuid4(),
+ 'post_content' => wp_json_encode( array(
+ 'sidebars_widgets[sidebar-1]' => array(
+ 'value' => $new_sidebar_1,
+ ),
+ ) ),
+ ) );
+
+ // Save the updated sidebar widgets into the options table by publishing the changeset.
+ wp_publish_post( $post_id );
+
+ // Make sure previewing filters were never added, since WP_Customize_Manager should be constructed with settings_previewed=false.
+ $this->assertFalse( has_filter( 'option_sidebars_widgets' ) );
+ $this->assertFalse( has_filter( 'default_option_sidebars_widgets' ) );
+
+ // Ensure that the value has actually been written to the DB.
+ $updated_sidebars_widgets = get_option( 'sidebars_widgets' );
+ $this->assertEquals( $new_sidebar_1, $updated_sidebars_widgets['sidebar-1'] );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Ensure that save_changeset_post method bails updating an underlying changeset which is invalid.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 41252
</span></span></pre>
</div>
</div>
</body>
</html>