Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 31602e0

Browse files
committed
Remove dirty from codebase and deprecate when used in set method
1 parent 182c8c8 commit 31602e0

5 files changed

+51
-55
lines changed

php/class-customize-snapshot-manager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ public function save( $status = 'draft' ) {
567567
foreach ( $this->customize_manager->settings() as $setting ) {
568568
if ( $this->can_preview( $setting, $this->unsanitized_snapshot_post_data ) ) {
569569
$post_data = $this->unsanitized_snapshot_post_data[ $setting->id ];
570-
$this->snapshot->set( $setting, $post_data['value'], $post_data['dirty'] );
570+
$this->snapshot->set( $setting, $post_data['value'] );
571571
}
572572
}
573573

php/class-customize-snapshot.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -336,18 +336,24 @@ public function status() {
336336
/**
337337
* Store a setting's value in the snapshot's data.
338338
*
339-
* @param \WP_Customize_Setting $setting Setting.
340-
* @param mixed $value Must be JSON-serializable.
341-
* @param bool $dirty Whether the setting is dirty or not.
339+
* @since 0.4.0 Removed support for `$dirty` argument.
340+
*
341+
* @param \WP_Customize_Setting $setting Setting.
342+
* @param mixed $value Must be JSON-serializable.
343+
* @param bool $deprecated Whether the setting is dirty or not.
342344
*/
343-
public function set( \WP_Customize_Setting $setting, $value, $dirty ) {
344-
if ( $dirty ) {
345-
$this->data[ $setting->id ] = array(
346-
'value' => $value,
347-
'dirty' => $dirty,
348-
'sanitized' => false,
349-
);
345+
public function set( \WP_Customize_Setting $setting, $value, $deprecated = null ) {
346+
if ( ! is_null( $deprecated ) ) {
347+
_doing_it_wrong( __METHOD__, 'The $dirty argument has been removed.', '0.4.0' );
348+
if ( false === $deprecated ) {
349+
return;
350+
}
350351
}
352+
353+
$this->data[ $setting->id ] = array(
354+
'value' => $value,
355+
'sanitized' => false,
356+
);
351357
}
352358

353359
/**

tests/php/test-class-ajax-customize-snapshot-manager.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function test_ajax_update_snapshot_preview_check() {
236236
'action' => Customize_Snapshot_Manager::AJAX_ACTION,
237237
'nonce' => wp_create_nonce( Customize_Snapshot_Manager::AJAX_ACTION ),
238238
'customize_snapshot_uuid' => self::UUID,
239-
'snapshot_customized' => '{"header_background_color":{"value":"#ffffff","dirty":false}}',
239+
'snapshot_customized' => '{"header_background_color":{"value":"#ffffff"}}',
240240
);
241241

242242
$this->manager->capture_unsanitized_snapshot_post_data();
@@ -260,7 +260,7 @@ function test_ajax_update_snapshot_success() {
260260
'action' => Customize_Snapshot_Manager::AJAX_ACTION,
261261
'nonce' => wp_create_nonce( Customize_Snapshot_Manager::AJAX_ACTION ),
262262
'customize_snapshot_uuid' => self::UUID,
263-
'snapshot_customized' => '{"foo":{"value":"foo_default","dirty":true},"bar":{"value":"bar_default","dirty":true}}',
263+
'snapshot_customized' => '{"foo":{"value":"foo_default"},"bar":{"value":"bar_default"}}',
264264
'preview' => 'off',
265265
);
266266

@@ -289,7 +289,7 @@ function test_ajax_update_snapshot_success_preview() {
289289
'action' => Customize_Snapshot_Manager::AJAX_ACTION,
290290
'nonce' => wp_create_nonce( Customize_Snapshot_Manager::AJAX_ACTION ),
291291
'customize_snapshot_uuid' => self::UUID,
292-
'snapshot_customized' => '{"foo":{"value":"foo_default","dirty":false},"bar":{"value":"bar_default","dirty":false}}',
292+
'snapshot_customized' => '{"foo":{"value":"foo_default"},"bar":{"value":"bar_default"}}',
293293
'preview' => 'on',
294294
);
295295

@@ -303,7 +303,7 @@ function test_ajax_update_snapshot_success_preview() {
303303
// Get the results.
304304
$response = json_decode( $this->_last_response, true );
305305
$this->assertSame( self::UUID, $response['data']['customize_snapshot_uuid'] );
306-
$this->assertEmpty( $response['data']['customize_snapshot_settings'] );
306+
$this->assertNotEmpty( $response['data']['customize_snapshot_settings'] );
307307
}
308308

309309
/**

tests/php/test-class-customize-snapshot-manager.php

+18-19
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ function test_filter_post_row_actions_draft() {
202202
$_POST = array(
203203
'nonce' => wp_create_nonce( 'save-customize_' . $this->wp_customize->get_stylesheet() ),
204204
'snapshot_uuid' => self::UUID,
205-
'snapshot_customized' => '{"foo":{"value":"foo_default","dirty":true},"bar":{"value":"bar_default","dirty":true}}',
205+
'snapshot_customized' => '{"foo":{"value":"foo_default"},"bar":{"value":"bar_default"}}',
206206
);
207207

208208
$manager = new Customize_Snapshot_Manager( $this->plugin );
209209
$manager->capture_unsanitized_snapshot_post_data();
210210
$foo = $manager->customize_manager->get_setting( 'foo' );
211-
$manager->snapshot()->set( $foo, 'foo_custom', true );
211+
$manager->snapshot()->set( $foo, 'foo_custom' );
212212
$manager->snapshot()->save();
213213
$actions = array(
214214
'inline hide-if-no-js' => true,
@@ -230,7 +230,7 @@ function test_filter_post_row_actions_publish() {
230230
$_POST = array(
231231
'nonce' => wp_create_nonce( 'save-customize_' . $this->wp_customize->get_stylesheet() ),
232232
'snapshot_uuid' => self::UUID,
233-
'snapshot_customized' => '{"foo":{"value":"foo_default","dirty":true},"bar":{"value":"bar_default","dirty":true}}',
233+
'snapshot_customized' => '{"foo":{"value":"foo_default"},"bar":{"value":"bar_default"}}',
234234
);
235235
$manager = new Customize_Snapshot_Manager( $this->plugin );
236236
$manager->set_snapshot_uuid();
@@ -264,7 +264,7 @@ function test_setup_metaboxes() {
264264
function test_render_data_metabox() {
265265
wp_set_current_user( $this->user_id );
266266
$this->do_customize_boot_actions( true );
267-
$snapshot_json = '{"foo":{"value":"foo_value","dirty":true,"sanitized":false}}';
267+
$snapshot_json = '{"foo":{"value":"foo_value","sanitized":false}}';
268268
$_POST = array(
269269
'nonce' => wp_create_nonce( 'save-customize_' . $this->wp_customize->get_stylesheet() ),
270270
'snapshot_uuid' => self::UUID,
@@ -273,7 +273,7 @@ function test_render_data_metabox() {
273273
$manager = new Customize_Snapshot_Manager( $this->plugin );
274274
$manager->capture_unsanitized_snapshot_post_data();
275275
$foo = $manager->customize_manager->get_setting( 'foo' );
276-
$manager->snapshot()->set( $foo, 'foo_value', true );
276+
$manager->snapshot()->set( $foo, 'foo_value' );
277277
$manager->snapshot()->save();
278278
$post = $manager->snapshot()->post();
279279
ob_start();
@@ -290,7 +290,7 @@ function test_render_data_metabox() {
290290
function test_get_post_content() {
291291
wp_set_current_user( $this->user_id );
292292
$this->do_customize_boot_actions( true );
293-
$snapshot_json = '{"foo":{"value":"foo_value","dirty":true,"sanitized":false}}';
293+
$snapshot_json = '{"foo":{"value":"foo_value","sanitized":false}}';
294294
$_POST = array(
295295
'nonce' => wp_create_nonce( 'save-customize_' . $this->wp_customize->get_stylesheet() ),
296296
'snapshot_uuid' => self::UUID,
@@ -299,14 +299,14 @@ function test_get_post_content() {
299299
$manager = new Customize_Snapshot_Manager( $this->plugin );
300300
$manager->capture_unsanitized_snapshot_post_data();
301301
$foo = $manager->customize_manager->get_setting( 'foo' );
302-
$manager->snapshot()->set( $foo, 'foo_value', true );
302+
$manager->snapshot()->set( $foo, 'foo_value' );
303303
$manager->snapshot()->save();
304304
$post = $manager->snapshot()->post();
305305
$snapshot_content = Customize_Snapshot_Manager::get_post_content( $post );
306306
$this->assertEquals( json_decode( $snapshot_json, true ), $snapshot_content );
307307

308308
// Get the revision post.
309-
$manager->snapshot()->set( $foo, 'foo_revision_value', true );
309+
$manager->snapshot()->set( $foo, 'foo_revision_value' );
310310
$manager->snapshot()->save();
311311
$revisions = wp_get_post_revisions( $post->ID );
312312
$revision = array_shift( $revisions );
@@ -334,11 +334,10 @@ function test_encode_json() {
334334
$array = array(
335335
'foo' => array(
336336
'value' => 'foo_value',
337-
'dirty' => true,
338337
'sanitized' => false,
339338
),
340339
);
341-
$json = '{"foo":{"value":"foo_value","dirty":true,"sanitized":false}}';
340+
$json = '{"foo":{"value":"foo_value","sanitized":false}}';
342341
$this->assertEquals( $json, preg_replace( '/\s+/', '', Customize_Snapshot_Manager::encode_json( $array ) ) );
343342
}
344343

@@ -353,7 +352,7 @@ function test_enqueue_scripts() {
353352
$_POST = array(
354353
'nonce' => wp_create_nonce( 'save-customize_' . $this->wp_customize->get_stylesheet() ),
355354
'snapshot_uuid' => self::UUID,
356-
'snapshot_customized' => '{"foo":{"value":"foo_default","dirty":false},"bar":{"value":"bar_default","dirty":false}}',
355+
'snapshot_customized' => '{"foo":{"value":"foo_default"},"bar":{"value":"bar_default"}}',
357356
);
358357
$manager = new Customize_Snapshot_Manager( $this->plugin );
359358
$manager->set_snapshot_uuid();
@@ -387,7 +386,7 @@ function test_save_error() {
387386
$_POST = array(
388387
'nonce' => wp_create_nonce( 'save-customize_' . $this->wp_customize->get_stylesheet() ),
389388
'snapshot_uuid' => self::UUID,
390-
'snapshot_customized' => '{"baz":{"value":"","dirty":true}}',
389+
'snapshot_customized' => '{"baz":{"value":""}}',
391390
);
392391
$manager = new Customize_Snapshot_Manager( $this->plugin );
393392
$manager->save();
@@ -403,7 +402,7 @@ function test_save_snapshot() {
403402
$_POST = array(
404403
'nonce' => wp_create_nonce( 'save-customize_' . $this->wp_customize->get_stylesheet() ),
405404
'snapshot_uuid' => self::UUID,
406-
'snapshot_customized' => '{"foo":{"value":"foo_default","dirty":false},"bar":{"value":"bar_default","dirty":false}}',
405+
'snapshot_customized' => '{"foo":{"value":"foo_default"},"bar":{"value":"bar_default"}}',
407406
);
408407
$manager = new Customize_Snapshot_Manager( $this->plugin );
409408
$manager->set_snapshot_uuid();
@@ -465,7 +464,7 @@ public function test_can_preview() {
465464
$_POST = wp_slash( array(
466465
'nonce' => wp_create_nonce( 'save-customize_' . $this->wp_customize->get_stylesheet() ),
467466
'snapshot_uuid' => self::UUID,
468-
'snapshot_customized' => '{"foo":{"value":"foo_custom","dirty":true},"bar":{"value":"bar_default","dirty":false}}',
467+
'snapshot_customized' => '{"foo":{"value":"foo_custom"},"bar":{"value":"bar_default"}}',
469468
) );
470469
$this->do_customize_boot_actions( true );
471470
$foo = $this->wp_customize->get_setting( 'foo' );
@@ -503,7 +502,7 @@ public function test_can_preview_array_key_exists() {
503502
$_POST = array(
504503
'nonce' => wp_create_nonce( 'save-customize_' . $this->wp_customize->get_stylesheet() ),
505504
'snapshot_uuid' => self::UUID,
506-
'snapshot_customized' => '{"bar":{"value":"bar_default","dirty":false}}',
505+
'snapshot_customized' => '{"bar":{"value":"bar_default"}}',
507506
);
508507
$manager = new Customize_Snapshot_Manager( $this->plugin );
509508
$manager->save_snapshot();
@@ -520,7 +519,7 @@ public function test_can_preview_array_key_exists() {
520519
public function test_set_post_values() {
521520
wp_set_current_user( $this->user_id );
522521
$foo = $this->manager->customize_manager->get_setting( 'foo' );
523-
$this->manager->snapshot()->set( $foo, 'foo_custom', true );
522+
$this->manager->snapshot()->set( $foo, 'foo_custom' );
524523
$this->manager->snapshot()->save();
525524
$this->manager->snapshot()->is_preview = true;
526525
$this->manager->set_post_values();
@@ -535,7 +534,7 @@ public function test_preview() {
535534
$this->manager->customize_manager = $this->wp_customize;
536535
$this->manager->snapshot = new Customize_Snapshot( $this->manager, null );
537536
$foo = $this->manager->customize_manager->get_setting( 'foo' );
538-
$this->manager->snapshot()->set( $foo, 'foo_custom', true );
537+
$this->manager->snapshot()->set( $foo, 'foo_custom' );
539538
$this->assertFalse( $foo->dirty );
540539
$this->manager->snapshot()->save();
541540
$this->manager->snapshot()->is_preview = true;
@@ -553,8 +552,8 @@ public function test_excerpt() {
553552
$this->manager->snapshot = new Customize_Snapshot( $this->manager, null );
554553
$foo = $this->manager->customize_manager->get_setting( 'foo' );
555554
$bar = $this->manager->customize_manager->get_setting( 'bar' );
556-
$this->manager->snapshot()->set( $foo, 'foo_custom', true );
557-
$this->manager->snapshot()->set( $bar, 'bar_custom', true );
555+
$this->manager->snapshot()->set( $foo, 'foo_custom' );
556+
$this->manager->snapshot()->set( $bar, 'bar_custom' );
558557
$this->manager->snapshot()->save();
559558

560559
$post = $this->manager->snapshot()->post();

tests/php/test-class-customize-snapshot.php

+12-21
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,9 @@ function test_values() {
187187
$_POST['customized'] = 'on';
188188
$this->wp_customize->setup_theme();
189189

190-
// Has no no dirty values.
191-
$snapshot = new Customize_Snapshot( $this->snapshot_manager, null );
192-
$snapshot->set( $this->foo, 'foo_default', false );
193-
$snapshot->set( $this->bar, 'bar_default', false );
194-
$this->assertEmpty( $snapshot->values() );
195-
$snapshot->save();
196-
$uuid = $snapshot->uuid();
197-
198190
// Has dirty values.
199-
$snapshot = new Customize_Snapshot( $this->snapshot_manager, $uuid );
200-
$snapshot->set( $this->bar, 'bar_custom', true );
191+
$snapshot = new Customize_Snapshot( $this->snapshot_manager, null );
192+
$snapshot->set( $this->bar, 'bar_custom' );
201193
$this->assertNotEmpty( $snapshot->values() );
202194
}
203195

@@ -210,13 +202,12 @@ function test_data() {
210202
$this->wp_customize->setup_theme();
211203

212204
$snapshot = new Customize_Snapshot( $this->snapshot_manager, null );
213-
$snapshot->set( $this->foo, 'foo_default', false );
214-
$this->assertEmpty( $snapshot->data() );
215-
$snapshot->set( $this->foo, 'foo_custom', true );
205+
$snapshot->set( $this->foo, 'foo_default' );
206+
$this->assertNotEmpty( $snapshot->data() );
207+
$snapshot->set( $this->foo, 'foo_custom' );
216208
$expected = array(
217209
'foo' => array(
218210
'value' => 'foo_custom',
219-
'dirty' => true,
220211
'sanitized' => false,
221212
),
222213
);
@@ -229,7 +220,7 @@ function test_data() {
229220
function test_settings() {
230221
$snapshot = new Customize_Snapshot( $this->snapshot_manager, null );
231222
$this->assertEmpty( $snapshot->settings() );
232-
$snapshot->set( $this->foo, 'foo_default', true );
223+
$snapshot->set( $this->foo, 'foo_default' );
233224
$this->assertNotEmpty( $snapshot->settings() );
234225
}
235226

@@ -242,12 +233,12 @@ function test_set_and_get() {
242233

243234
$this->wp_customize->add_setting( 'biz' );
244235
$this->assertEmpty( $snapshot->get( $this->wp_customize->get_setting( 'biz' ) ) );
245-
$snapshot->set( $this->foo, 'foo_default', false );
236+
$snapshot->set( $this->foo, 'foo_default' );
246237
$this->assertNotEmpty( $snapshot->get( $this->foo ) );
247238
$this->assertNotEmpty( $snapshot->get( 'foo' ) );
248239
$this->assertEquals( 'bar_default', $snapshot->get( 'bar' ) );
249240
$this->assertEquals( 'default', $snapshot->get( 'bar', 'default' ) );
250-
$this->assertNull( $snapshot->get( 'baz' ) );
241+
$this->assertNull( $snapshot->get( 'baz' ) );
251242
}
252243

253244
/**
@@ -256,8 +247,8 @@ function test_set_and_get() {
256247
function test_save() {
257248
$snapshot = new Customize_Snapshot( $this->snapshot_manager, null );
258249

259-
$snapshot->set( $this->foo, 'foo_default', true );
260-
$snapshot->set( $this->bar, 'bar_default', true );
250+
$snapshot->set( $this->foo, 'foo_default' );
251+
$snapshot->set( $this->bar, 'bar_default' );
261252

262253
$this->assertFalse( $snapshot->saved() );
263254
$snapshot->save();
@@ -270,7 +261,7 @@ function test_save() {
270261

271262
// Update the Snapshot content
272263
$snapshot = new Customize_Snapshot( $this->snapshot_manager, $snapshot->uuid() );
273-
$snapshot->set( $this->bar, 'bar_custom', true );
264+
$snapshot->set( $this->bar, 'bar_custom' );
274265

275266
$snapshot->save( 'publish' );
276267
$decoded = json_decode( $snapshot->post()->post_content, true );
@@ -298,7 +289,7 @@ function test_save_pending() {
298289
wp_set_current_user( $contributor_id );
299290
$this->snapshot_manager->customize_manager = $wp_customize;
300291
$snapshot = new Customize_Snapshot( $this->snapshot_manager, null );
301-
$snapshot->set( $this->foo, 'foo', true );
292+
$snapshot->set( $this->foo, 'foo' );
302293
$uuid = $snapshot->uuid();
303294
$this->assertNotInstanceOf( 'WP_Error', $snapshot->save( 'pending' ) );
304295
$post = get_post( $snapshot->post() );

0 commit comments

Comments
 (0)