WordPress.org

Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #29316, comment 10


Ignore:
Timestamp:
09/30/2015 08:51:46 PM (4 years ago)
Author:
westonruter
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29316, comment 10

    initial v1  
    1 #34099 was marked as a duplicate.
     1#34099 was marked as a duplicate, as reported by @shramee:
     2
     3`WP_Customize_Setting::value()` doesn't allow filtering all settings with common custom customize setting type, whereas `WP_Customize_Setting::update()` and `WP_Customize_Setting::preview()` use hooks based on type name and provide access to properties of current instance ( passing `$this` as parameter ) hooked functions.
     4
     5All what's there for custom customize option type in update method is
     6{{{
     7return apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default );
     8}}}
     9Which falls short of serving the purpose because,
     101. `$this->id_data[ 'keys' ]` is very much required for array based values so `$this` (or at least `$this->id_data`) must be passed.
     112. Need to add it individually for each setting creating tons of duplication code smells.
     12
     13In my opinion
     14{{{
     15return apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default );
     16}}}
     17can be replaced with something like this...
     18{{{
     19$value = apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default );
     20if ( $this->default == $value ) {
     21        /**
     22         * Filter a Customize setting value not handled as a theme_mod or option.
     23         *
     24         * The dynamic portion of the hook name, `$this->type`, refers to the type of setting.
     25         *
     26         * For settings handled as theme_mods or options, see those corresponding
     27         * functions for available hooks.
     28         *
     29         * @since x.x.x
     30         *
     31         * @param mixed $default The setting default value. Default empty.
     32         * @param WP_Customize_Setting $this  WP_Customize_Setting instance.
     33         */
     34        return apply_filters( 'customize_value_' . $this->type, $this->default, $this );
     35}
     36return $value;
     37}}}