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.

Method of the class: 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() code WC 8.7.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;
}