Automattic\WooCommerce\Internal\Settings

OptionSanitizer::sanitize_color_option()privateWC 6.6.0

Sanitizes values for options of type 'color' before persisting to the database. Falls back to previous/default value for the option if given an invalid value.

Метод класса: OptionSanitizer{}

No Hooks.

Return

String. Color in hex format.

Usage

// private - for code of main (parent) class only
$result = $this->sanitize_color_option( $value, $option );
$value(string) (required)
Option value.
$option(array) (required)
Option data.

Changelog

Since 6.6.0 Introduced.

Код OptionSanitizer::sanitize_color_option() WC 7.1.0

private function sanitize_color_option( $value, $option ) {
	$value = sanitize_hex_color( $value );

	// If invalid, try the current value.
	if ( ! $value && ! empty( $option['id'] ) ) {
		$value = sanitize_hex_color( get_option( $option['id'] ) );
	}

	// If still invalid, try the default.
	if ( ! $value && ! empty( $option['default'] ) ) {
		$value = sanitize_hex_color( $option['default'] );
	}

	return (string) $value;
}