WP_Customize_Setting::sanitize │ public │ WP 3.4.0

Sanitize an input.

Method of the class: WP_Customize_Setting{}

Hooks from the method

Returns

string|array|null|WP_Error. Sanitized value, or null/WP_Error if invalid.

Usage

$WP_Customize_Setting = new WP_Customize_Setting();
$WP_Customize_Setting->sanitize( $value );
$value(string|array) (required)
The value to sanitize.

Changelog

Since 3.4.0 Introduced.
Since 7.1.5 The value of an option setting is additionally sanitized with sanitize_option().

WP_Customize_Setting::sanitize() code WP 7.1.5

public function sanitize( $value ) {
	/**
	 * Filters a Customize setting value in un-slashed form.
	 *
	 * @since 3.4.0
	 *
	 * @param mixed                $value   Value of the setting.
	 * @param WP_Customize_Setting $setting WP_Customize_Setting instance.
	 */
	$value = apply_filters( "customize_sanitize_{$this->id}", $value, $this );

	/*
	 * The value of an option setting is previewed via the option filters, bypassing the
	 * sanitize_option() call in update_option(). So the value is sanitized here to ensure
	 * that the previewed value is sanitized in the same way as the value which would be
	 * persisted. When saving, this is skipped since update_option() sanitizes the value.
	 */
	if ( 'option' === $this->type && ! $this->is_saving && ! is_null( $value ) && ! is_wp_error( $value ) ) {
		$value = $this->sanitize_option_value( $value );
	}

	return $value;
}