customize_validate_(id) хук-фильтрWP 4.6.0

Validates a Customize setting value.

Plugins should amend the $validity object via its WP_Error::add() method.

The dynamic portion of the hook name, $this->ID, refers to the setting ID.

Использование

add_filter( 'customize_validate_(id)', 'wp_kama_customize_validate_id_filter', 10, 3 );

/**
 * Function for `customize_validate_(id)` filter-hook.
 * 
 * @param WP_Error             $validity Filtered from `true` to `WP_Error` when invalid.
 * @param mixed                $value    Value of the setting.
 * @param WP_Customize_Setting $setting  WP_Customize_Setting instance.
 *
 * @return WP_Error
 */
function wp_kama_customize_validate_id_filter( $validity, $value, $setting ){

	// filter...
	return $validity;
}
$validity(WP_Error)
Filtered from true to WP_Error when invalid.
$value(разное)
Value of the setting.
$setting(WP_Customize_Setting)
WP_Customize_Setting instance.

Список изменений

С версии 4.6.0 Введена.

Где вызывается хук

WP_Customize_Setting::validate()
customize_validate_(id)
wp-includes/class-wp-customize-setting.php 611
$validity = apply_filters( "customize_validate_{$this->id}", $validity, $value, $this );

Где используется хук в WordPress

wp-includes/class-wp-customize-setting.php 199
add_filter( "customize_validate_{$this->id}", $this->validate_callback, 10, 3 );