WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/02/2016 10:41:36 PM (3 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.