[wp-trac] [WordPress Trac] #34099: WP_Customize_Setting::value() custom type

WordPress Trac noreply at wordpress.org
Wed Sep 30 16:30:41 UTC 2015


#34099: WP_Customize_Setting::value() custom type
----------------------------+-----------------------------
 Reporter:  shramee         |      Owner:
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Customize       |    Version:  4.3.1
 Severity:  normal          |   Keywords:
  Focuses:  administration  |
----------------------------+-----------------------------
 WP_Customize_Setting::value() doesn't allow filtering all settings with
 common custom customize setting type,[[BR]]
 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,
 1. $this->id_data[ 'keys' ] is very much required for array based values
 so $this (or at least $this->id_data) must be passed.
 2. 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

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34099>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list