Changeset 34838
- Timestamp:
- 10/05/2015 09:57:32 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-setting.php
r33911 r34838 305 305 * 306 306 * @param mixed $value The value to update. 307 * @return mixedThe result of saving the value.307 * @return bool The result of saving the value. 308 308 */ 309 309 protected function update( $value ) { 310 switch ( $this->type ) {310 switch ( $this->type ) { 311 311 case 'theme_mod' : 312 return $this->_update_theme_mod( $value ); 312 $this->_update_theme_mod( $value ); 313 return true; 313 314 314 315 case 'option' : … … 328 329 * @param WP_Customize_Setting $this WP_Customize_Setting instance. 329 330 */ 330 return do_action( 'customize_update_' . $this->type, $value, $this ); 331 do_action( "customize_update_{$this->type}", $value, $this ); 332 333 return has_action( "customize_update_{$this->type}" ); 331 334 } 332 335 } -
trunk/tests/phpunit/tests/customize/setting.php
r32840 r34838 368 368 369 369 /** 370 * Test setting save method for custom type. 371 * 372 * @see WP_Customize_Setting::save() 373 * @see WP_Customize_Setting::update() 374 */ 375 function test_update_custom_type() { 376 $type = 'custom'; 377 $name = 'foo'; 378 $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) ); 379 $this->manager->add_setting( $setting ); 380 add_action( 'customize_update_custom', array( $this, 'handle_customize_update_custom_foo_action' ), 10, 2 ); 381 add_action( 'customize_save_foo', array( $this, 'handle_customize_save_custom_foo_action' ), 10, 2 ); 382 383 // Try saving before value set. 384 $this->assertTrue( 0 === did_action( 'customize_update_custom' ) ); 385 $this->assertTrue( 0 === did_action( 'customize_save_foo' ) ); 386 $this->assertFalse( $setting->save() ); 387 $this->assertTrue( 0 === did_action( 'customize_update_custom' ) ); 388 $this->assertTrue( 0 === did_action( 'customize_save_foo' ) ); 389 390 // Try setting post value without user as admin. 391 $this->manager->set_post_value( $setting->id, 'hello world' ); 392 $this->assertFalse( $setting->save() ); 393 $this->assertTrue( 0 === did_action( 'customize_update_custom' ) ); 394 $this->assertTrue( 0 === did_action( 'customize_save_foo' ) ); 395 396 // Satisfy all requirements for save to happen. 397 wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); 398 $this->assertTrue( false !== $setting->save() ); 399 $this->assertTrue( 1 === did_action( 'customize_update_custom' ) ); 400 $this->assertTrue( 1 === did_action( 'customize_save_foo' ) ); 401 } 402 403 /** 404 * Check customize_update_custom action. 405 * 406 * @see Tests_WP_Customize_Setting::test_update_custom_type() 407 * @param mixed $value 408 * @param WP_Customize_Setting $setting 409 */ 410 function handle_customize_update_custom_foo_action( $value, $setting = null ) { 411 $this->assertEquals( 'hello world', $value ); 412 $this->assertInstanceOf( 'WP_Customize_Setting', $setting ); 413 } 414 415 /** 416 * Check customize_save_foo action. 417 * 418 * @see Tests_WP_Customize_Setting::test_update_custom_type() 419 * @param WP_Customize_Setting $setting 420 */ 421 function handle_customize_save_custom_foo_action( $setting ) { 422 $this->assertInstanceOf( 'WP_Customize_Setting', $setting ); 423 $this->assertEquals( 'custom', $setting->type ); 424 $this->assertEquals( 'foo', $setting->id ); 425 } 426 427 /** 370 428 * Ensure that is_current_blog_previewed returns the expected values. 371 429 *
Note: See TracChangeset
for help on using the changeset viewer.