<!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>[39320] trunk: Customize: Ensure that `WP_Customize_Manager::save_changeset_post()` returns `setting_validities` even for supplied values that are unchanged from values in changeset.</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/39320">39320</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/39320","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>2016-11-19 22:38:40 +0000 (Sat, 19 Nov 2016)</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: Ensure that `WP_Customize_Manager::save_changeset_post()` returns `setting_validities` even for supplied values that are unchanged from values in changeset.

Check setting existence and authorization via `WP_Customize_Manager::validate_setting_values()` even for `null` values to account for custom params being added to settings, preventing failures from being silently ignored.

See <a href="https://core.trac.wordpress.org/ticket/38705">#38705</a>, <a href="https://core.trac.wordpress.org/ticket/30937">#30937</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/38865">#38865</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="#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      2016-11-19 11:04:30 UTC (rev 39319)
+++ trunk/src/wp-includes/class-wp-customize-manager.php        2016-11-19 22:38:40 UTC (rev 39320)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1728,12 +1728,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                                continue;
</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 ( is_null( $unsanitized_value ) ) {
-                               continue;
-                       }
</del><span class="cx" style="display: block; padding: 0 10px">                         if ( $options['validate_capability'] && ! current_user_can( $setting->capability ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $validity = new WP_Error( 'unauthorized', __( 'Unauthorized to modify setting due to capability.' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        } else {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                if ( is_null( $unsanitized_value ) ) {
+                                       continue;
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $validity = $setting->validate( $unsanitized_value );
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! is_wp_error( $validity ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2030,7 +2030,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                $changed_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">-                $post_values = wp_array_slice_assoc( $post_values, $changed_setting_ids );
</del><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">                 * Fires before save validation happens.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2046,7 +2045,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                do_action( 'customize_save_validation_before', $this );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Validate settings.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $setting_validities = $this->validate_setting_values( $post_values, array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $validated_values = array_merge(
+                       array_fill_keys( array_keys( $args['data'] ), null ), // Make sure existence/capability checks are done on value-less setting updates.
+                       $post_values
+               );
+               $setting_validities = $this->validate_setting_values( $validated_values, array(
</ins><span class="cx" style="display: block; padding: 0 10px">                         'validate_capability' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                        'validate_existence' => true,
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2064,10 +2067,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return new WP_Error( 'transaction_fail', '', $response );
</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">-                $response = array(
-                       'setting_validities' => $setting_validities,
-               );
-
</del><span class="cx" style="display: block; padding: 0 10px">                 // Obtain/merge data for changeset.
</span><span class="cx" style="display: block; padding: 0 10px">                $original_changeset_data = $this->get_changeset_post_data( $changeset_post_id );
</span><span class="cx" style="display: block; padding: 0 10px">                $data = $original_changeset_data;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2105,14 +2104,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                // Remove setting from changeset entirely.
</span><span class="cx" style="display: block; padding: 0 10px">                                unset( $data[ $changeset_setting_id ] );
</span><span class="cx" style="display: block; padding: 0 10px">                        } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // Merge any additional setting params that have been supplied with the existing params.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( ! isset( $data[ $changeset_setting_id ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        $data[ $changeset_setting_id ] = array();
</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">+                                // Merge any additional setting params that have been supplied with the existing params.
+                               $merged_setting_params = array_merge( $data[ $changeset_setting_id ], $setting_params );
+
+                               // Skip updating setting params if unchanged (ensuring the user_id is not overwritten).
+                               if ( $data[ $changeset_setting_id ] === $merged_setting_params ) {
+                                       continue;
+                               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $data[ $changeset_setting_id ] = array_merge(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        $data[ $changeset_setting_id ],
-                                       $setting_params,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 $merged_setting_params,
</ins><span class="cx" style="display: block; padding: 0 10px">                                         array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                'type' => $setting->type,
</span><span class="cx" style="display: block; padding: 0 10px">                                                'user_id' => $args['user_id'],
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2220,6 +2226,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                remove_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $response = array(
+                       'setting_validities' => $setting_validities,
+               );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( is_wp_error( $r ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $response['changeset_post_save_failure'] = $r->get_error_code();
</span><span class="cx" style="display: block; padding: 0 10px">                        return new WP_Error( 'changeset_post_save_failure', '', $response );
</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   2016-11-19 11:04:30 UTC (rev 39319)
+++ trunk/tests/phpunit/tests/customize/manager.php     2016-11-19 22:38:40 UTC (rev 39320)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -860,18 +860,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $other_admin_user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $uuid = wp_generate_uuid4();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $manager = new WP_Customize_Manager( array(
-                       'changeset_uuid' => $uuid,
-               ) );
-               $wp_customize = $manager;
-               do_action( 'customize_register', $manager );
-               $manager->add_setting( 'scratchpad', array(
-                       'type' => 'option',
-                       'capability' => 'exist',
-               ) );
-
-               // Create initial set of
-               $r = $manager->save_changeset_post( array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $wp_customize = $this->create_test_manager( $uuid );
+               $r = $wp_customize->save_changeset_post( array(
</ins><span class="cx" style="display: block; padding: 0 10px">                         'status' => 'auto-draft',
</span><span class="cx" style="display: block; padding: 0 10px">                        'data' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'blogname' => array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -890,7 +880,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        array_fill_keys( array( 'blogname', 'scratchpad', 'background_color' ), true ),
</span><span class="cx" style="display: block; padding: 0 10px">                        $r['setting_validities']
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $post_id = $manager->find_changeset_post_id( $uuid );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $post_id = $wp_customize->find_changeset_post_id( $uuid );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $data = json_decode( get_post( $post_id )->post_content, true );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( self::$admin_user_id, $data['blogname']['user_id'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( self::$admin_user_id, $data['scratchpad']['user_id'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -898,7 +888,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Attempt to save just one setting under a different user.
</span><span class="cx" style="display: block; padding: 0 10px">                wp_set_current_user( $other_admin_user_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $r = $manager->save_changeset_post( array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $wp_customize = $this->create_test_manager( $uuid );
+               $r = $wp_customize->save_changeset_post( array(
</ins><span class="cx" style="display: block; padding: 0 10px">                         'status' => 'auto-draft',
</span><span class="cx" style="display: block; padding: 0 10px">                        'data' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'blogname' => array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -923,9 +914,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $other_admin_user_id, $data[ $this->manager->get_stylesheet() . '::background_color' ]['user_id'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Attempt to save now as under-privileged user.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $r = $manager->save_changeset_post( array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $wp_customize = $this->create_test_manager( $uuid );
+               $r = $wp_customize->save_changeset_post( array(
</ins><span class="cx" style="display: block; padding: 0 10px">                         'status' => 'auto-draft',
</span><span class="cx" style="display: block; padding: 0 10px">                        'data' => array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'blogname' => array(
+                                       'value' => 'Admin 2 Title', // Identical to what is already in the changeset so will be skipped.
+                               ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'scratchpad' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'value' => 'Subscriber Scratch',
</span><span class="cx" style="display: block; padding: 0 10px">                                ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -934,11 +929,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertInternalType( 'array', $r );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        array_fill_keys( array( 'scratchpad' ), true ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 array_fill_keys( array( 'scratchpad', 'blogname' ), true ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         $r['setting_validities']
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">                $data = json_decode( get_post( $post_id )->post_content, true );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( $other_admin_user_id, $data['blogname']['user_id'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( $other_admin_user_id, $data['blogname']['user_id'], 'Expected setting to be untouched.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertEquals( self::$subscriber_user_id, $data['scratchpad']['user_id'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $other_admin_user_id, $data[ $this->manager->get_stylesheet() . '::background_color' ]['user_id'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -955,7 +950,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $save_counts[ $setting_id ] = did_action( sprintf( 'customize_save_%s', $setting_id ) );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                $this->filtered_setting_current_user_ids = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                foreach ( $manager->settings() as $setting ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         foreach ( $wp_customize->settings() as $setting ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         add_filter( sprintf( 'customize_sanitize_%s', $setting->id ), array( $this, 'filter_customize_setting_to_log_current_user' ), 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                wp_update_post( array( 'ID' => $post_id, 'post_status' => 'publish' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -972,6 +967,115 @@
</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">+         * Create test manager.
+        *
+        * @param string $uuid Changeset UUID.
+        * @return WP_Customize_Manager Manager.
+        */
+       protected function create_test_manager( $uuid ) {
+               $manager = new WP_Customize_Manager( array(
+                       'changeset_uuid' => $uuid,
+               ) );
+               do_action( 'customize_register', $manager );
+               $manager->add_setting( 'blogfounded', array(
+                       'type' => 'option',
+               ) );
+               $manager->add_setting( 'blogterminated', array(
+                       'type' => 'option',
+                       'capability' => 'do_not_allow',
+               ) );
+               $manager->add_setting( 'scratchpad', array(
+                       'type' => 'option',
+                       'capability' => 'exist',
+               ) );
+               return $manager;
+       }
+
+       /**
+        * Test writing changesets when user supplies unchanged values.
+        *
+        * @ticket 38865
+        * @covers WP_Customize_Manager::save_changeset_post()
+        */
+       function test_save_changeset_post_with_unchanged_values() {
+               global $wp_customize;
+
+               add_theme_support( 'custom-background' );
+               wp_set_current_user( self::$admin_user_id );
+               $other_admin_user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+
+               $uuid = wp_generate_uuid4();
+               $wp_customize = $this->create_test_manager( $uuid );
+               $wp_customize->save_changeset_post( array(
+                       'status' => 'auto-draft',
+                       'data' => array(
+                               'blogname' => array(
+                                       'value' => 'Admin 1 Title',
+                               ),
+                               'blogdescription' => array(
+                                       'value' => 'Admin 1 Tagline',
+                               ),
+                               'blogfounded' => array(
+                                       'value' => '2016',
+                               ),
+                               'scratchpad' => array(
+                                       'value' => 'Admin 1 Scratch',
+                               ),
+                       ),
+               ) );
+
+               // Make sure that setting properties of unknown and unauthorized settings are rejected.
+               $data = get_post( $wp_customize->changeset_post_id() )->post_content;
+               $r = $wp_customize->save_changeset_post( array(
+                       'data' => array(
+                               'unknownsetting' => array(
+                                       'custom' => 'prop',
+                               ),
+                               'blogterminated' => array(
+                                       'custom' => 'prop',
+                               ),
+                       ),
+               ) );
+               $this->assertInstanceOf( 'WP_Error', $r['setting_validities']['unknownsetting'] );
+               $this->assertEquals( 'unrecognized', $r['setting_validities']['unknownsetting']->get_error_code() );
+               $this->assertInstanceOf( 'WP_Error', $r['setting_validities']['blogterminated'] );
+               $this->assertEquals( 'unauthorized', $r['setting_validities']['blogterminated']->get_error_code() );
+               $this->assertEquals( $data, get_post( $wp_customize->changeset_post_id() )->post_content );
+
+               // Test submitting data with changed and unchanged settings, creating a new instance so that the post_values are cleared.
+               wp_set_current_user( $other_admin_user_id );
+               $wp_customize = $this->create_test_manager( $uuid );
+               $r = $wp_customize->save_changeset_post( array(
+                       'status' => 'auto-draft',
+                       'data' => array(
+                               'blogname' => array(
+                                       'value' => 'Admin 1 Title', // Unchanged value.
+                               ),
+                               'blogdescription' => array(
+                                       'value' => 'Admin 1 Tagline Changed', // Changed value.
+                               ),
+                               'blogfounded' => array(
+                                       'extra' => 'blogfounded_param', // New param.
+                               ),
+                               'scratchpad' => array(
+                                       'value' => 'Admin 1 Scratch', // Unchanged value.
+                                       'extra' => 'background_scratchpad2', // New param.
+                               ),
+                       ),
+               ) );
+
+               // Note that blogfounded is not included among setting_validities because no value was supplied and it is not unrecognized/unauthorized.
+               $this->assertEquals( array_fill_keys( array( 'blogname', 'blogdescription', 'scratchpad' ), true ), $r['setting_validities'], 'Expected blogname even though unchanged.' );
+
+               $data = json_decode( get_post( $wp_customize->changeset_post_id() )->post_content, true );
+
+               $this->assertEquals( self::$admin_user_id, $data['blogname']['user_id'], 'Expected unchanged user_id since value was unchanged.' );
+               $this->assertEquals( $other_admin_user_id, $data['blogdescription']['user_id'] );
+               $this->assertEquals( $other_admin_user_id, $data['blogfounded']['user_id'] );
+               $this->assertEquals( $other_admin_user_id, $data['scratchpad']['user_id'] );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Test writing changesets and publishing with users who can unfiltered_html and those who cannot.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 38705
</span></span></pre>
</div>
</div>

</body>
</html>