Customize: Pass WP_Customize_Setting
instance as second argument to customize_value_{$id_base}
filter.
Adds parity with setting instance being passed as second argument to `customize_sanitize_{$id}` and `customize_sanitize_js_{$id}`. Allows the actual ID of the (multidimensional) setting value being filtered to be inspected. Props celloexpressions, westonruter. Fixes #36452. git-svn-id: https://develop.svn.wordpress.org/trunk@37350 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e85c0d94b9
commit
018f988654
@ -657,11 +657,13 @@ class WP_Customize_Setting {
|
||||
* functions for available hooks.
|
||||
*
|
||||
* @since 3.4.0
|
||||
* @since 4.6.0 Added the `$this` setting instance as the second param.
|
||||
*
|
||||
* @param mixed $default The setting default value. Default empty.
|
||||
* @param mixed $default The setting default value. Default empty.
|
||||
* @param WP_Customize_Setting $this The setting instance.
|
||||
*/
|
||||
$value = apply_filters( "customize_value_{$id_base}", $value );
|
||||
} else if ( $this->is_multidimensional_aggregated ) {
|
||||
$value = apply_filters( "customize_value_{$id_base}", $value, $this );
|
||||
} elseif ( $this->is_multidimensional_aggregated ) {
|
||||
$root_value = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];
|
||||
$value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default );
|
||||
} else {
|
||||
|
@ -277,8 +277,19 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
|
||||
$this->custom_type_data_saved[ $name ] = $value;
|
||||
}
|
||||
|
||||
function custom_type_value_filter( $default ) {
|
||||
/**
|
||||
* Filter for `customize_value_{$id_base}`.
|
||||
*
|
||||
* @param mixed $default
|
||||
* @param WP_Customize_Setting $setting
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
function custom_type_value_filter( $default, $setting = null ) {
|
||||
$name = preg_replace( '/^customize_value_/', '', current_filter() );
|
||||
$this->assertInstanceOf( 'WP_Customize_Setting', $setting );
|
||||
$id_data = $setting->id_data();
|
||||
$this->assertEquals( $name, $id_data['base'] );
|
||||
return $this->custom_type_getter( $name, $default );
|
||||
}
|
||||
|
||||
@ -314,7 +325,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
|
||||
$default = "default_value_{$name}";
|
||||
$setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) );
|
||||
// Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need.
|
||||
add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) );
|
||||
add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ), 10, 2 );
|
||||
$this->assertEquals( $this->undefined, $this->custom_type_getter( $name, $this->undefined ) );
|
||||
$this->assertEquals( $default, $setting->value() );
|
||||
$this->assertTrue( $setting->preview() );
|
||||
@ -330,7 +341,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
|
||||
$this->custom_type_setter( $name, $initial_value );
|
||||
$setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) );
|
||||
// Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need.
|
||||
add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) );
|
||||
add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ), 10, 2 );
|
||||
$this->assertEquals( $initial_value, $this->custom_type_getter( $name, $this->undefined ) );
|
||||
$this->assertEquals( $initial_value, $setting->value() );
|
||||
$this->assertFalse( $setting->preview(), "Preview for $setting->id should not apply because existing type without an override." );
|
||||
@ -350,7 +361,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
|
||||
$default = "default_value_{$name}";
|
||||
$setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) );
|
||||
// Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need.
|
||||
add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) );
|
||||
add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ), 10, 2 );
|
||||
$this->assertEquals( $this->undefined, $this->custom_type_getter( $name, $this->undefined ) );
|
||||
$this->assertEquals( $default, $setting->value() );
|
||||
$this->assertTrue( $setting->preview() );
|
||||
@ -366,7 +377,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
|
||||
$this->custom_type_setter( $name, $initial_value );
|
||||
$setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) );
|
||||
// Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need.
|
||||
add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) );
|
||||
add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ), 10, 2 );
|
||||
$this->assertEquals( $initial_value, $this->custom_type_getter( $name, $this->undefined ) );
|
||||
$this->assertEquals( $initial_value, $setting->value() );
|
||||
$this->assertTrue( $setting->preview() );
|
||||
|
Loading…
Reference in New Issue
Block a user