Opened 8 years ago
Closed 8 years ago
#34099 closed enhancement (duplicate)
WP_Customize_Setting::value() custom type
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.3.1 |
Component: | Customize | Keywords: | |
Focuses: | administration | Cc: |
Description
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.
All what's there for custom customize option type in update method is
return apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default );
Which falls short of serving the purpose because,
- $this->id_data[ 'keys' ] is very much required for array based values so $this (or at least $this->id_data) must be passed.
- Need to add it individually for each setting creating tons of duplication code smells.
In my opinion
return apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default );
can be replaced with something like this...
$value = apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default ); if ( $this->default == $value ) { /** * Filter a Customize setting value not handled as a theme_mod or option. * * The dynamic portion of the hook name, `$this->type`, refers to the type of setting. * * For settings handled as theme_mods or options, see those corresponding * functions for available hooks. * * @since x.x.x * * @param mixed $default The setting default value. Default empty. * @param WP_Customize_Setting $this WP_Customize_Setting instance. */ return apply_filters( 'customize_value_' . $this->type, $this->default, $this ); } return $value;
Cheers
Change History (1)
Note: See
TracTickets for help on using
tickets.
@shramee: Thank you for the report. You're absolutely right, and there is actually an existing ticket for this. Please watch #29316.