WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#34099 closed enhancement (duplicate)

WP_Customize_Setting::value() custom type

Reported by: shramee Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3.1
Component: Customize Keywords:
Focuses: administration Cc:
PR Number:

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,

  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

Change History (1)

#1 @westonruter
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

@shramee: Thank you for the report. You're absolutely right, and there is actually an existing ticket for this. Please watch #29316.

Note: See TracTickets for help on using tickets.