WordPress.org

Make WordPress Core

Changeset 37350


Ignore:
Timestamp:
05/02/2016 10:41:36 PM (4 years ago)
Author:
westonruter
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-setting.php

    r37342 r37350  
    658658             *
    659659             * @since 3.4.0
     660             * @since 4.6.0 Added the `$this` setting instance as the second param.
    660661             *
    661              * @param mixed $default The setting default value. Default empty.
     662             * @param mixed                $default The setting default value. Default empty.
     663             * @param WP_Customize_Setting $this    The setting instance.
    662664             */
    663             $value = apply_filters( "customize_value_{$id_base}", $value );
    664         } else if ( $this->is_multidimensional_aggregated ) {
     665            $value = apply_filters( "customize_value_{$id_base}", $value, $this );
     666        } elseif ( $this->is_multidimensional_aggregated ) {
    665667            $root_value = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];
    666668            $value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default );
  • trunk/tests/phpunit/tests/customize/setting.php

    r36622 r37350  
    278278    }
    279279
    280     function custom_type_value_filter( $default ) {
     280    /**
     281     * Filter for `customize_value_{$id_base}`.
     282     *
     283     * @param mixed $default
     284     * @param WP_Customize_Setting $setting
     285     *
     286     * @return mixed|null
     287     */
     288    function custom_type_value_filter( $default, $setting = null ) {
    281289        $name = preg_replace( '/^customize_value_/', '', current_filter() );
     290        $this->assertInstanceOf( 'WP_Customize_Setting', $setting );
     291        $id_data = $setting->id_data();
     292        $this->assertEquals( $name, $id_data['base'] );
    282293        return $this->custom_type_getter( $name, $default );
    283294    }
     
    315326        $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) );
    316327        // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need.
    317         add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) );
     328        add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ), 10, 2 );
    318329        $this->assertEquals( $this->undefined, $this->custom_type_getter( $name, $this->undefined ) );
    319330        $this->assertEquals( $default, $setting->value() );
     
    331342        $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) );
    332343        // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need.
    333         add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) );
     344        add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ), 10, 2 );
    334345        $this->assertEquals( $initial_value, $this->custom_type_getter( $name, $this->undefined ) );
    335346        $this->assertEquals( $initial_value, $setting->value() );
     
    351362        $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) );
    352363        // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need.
    353         add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) );
     364        add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ), 10, 2 );
    354365        $this->assertEquals( $this->undefined, $this->custom_type_getter( $name, $this->undefined ) );
    355366        $this->assertEquals( $default, $setting->value() );
     
    367378        $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) );
    368379        // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need.
    369         add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) );
     380        add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ), 10, 2 );
    370381        $this->assertEquals( $initial_value, $this->custom_type_getter( $name, $this->undefined ) );
    371382        $this->assertEquals( $initial_value, $setting->value() );
Note: See TracChangeset for help on using the changeset viewer.