Automattic\WooCommerce\Internal\Settings
OptionSanitizer::sanitize_color_option
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.
Returns
String. Color in hex format.
Usage
$OptionSanitizer = new OptionSanitizer(); $OptionSanitizer->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() OptionSanitizer::sanitize color option code WC 10.8.1
public 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;
}