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 | |
| 5 | All what's there for custom customize option type in update method is |
| 6 | {{{ |
| 7 | return apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default ); |
| 8 | }}} |
| 9 | Which falls short of serving the purpose because, |
| 10 | 1. `$this->id_data[ 'keys' ]` is very much required for array based values so `$this` (or at least `$this->id_data`) must be passed. |
| 11 | 2. Need to add it individually for each setting creating tons of duplication code smells. |
| 12 | |
| 13 | In my opinion |
| 14 | {{{ |
| 15 | return apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default ); |
| 16 | }}} |
| 17 | can be replaced with something like this... |
| 18 | {{{ |
| 19 | $value = apply_filters( 'customize_value_' . $this->id_data[ 'base' ], $this->default ); |
| 20 | if ( $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 | } |
| 36 | return $value; |
| 37 | }}} |