Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Cover::validate_and_sanitize_color
Validate and sanitize a color value, returning empty string for invalid colors.
Method of the class: Cover{}
No Hooks.
Returns
String. Sanitized color or empty string if invalid.
Usage
// private - for code of main (parent) class only $result = $this->validate_and_sanitize_color( $color ): string;
- $color(string) (required)
- The color value to validate and sanitize.
Cover::validate_and_sanitize_color() Cover::validate and sanitize color code WC 10.4.3
private function validate_and_sanitize_color( string $color ): string {
$sanitized_color = Html_Processing_Helper::sanitize_color( $color );
// If sanitize_color returned the default fallback, check if the original was actually valid.
if ( '#000000' === $sanitized_color && '#000000' !== $color ) {
// The original color was invalid, so return empty string.
return '';
}
// The color is valid (either it was sanitized to something other than the default,
// or it was specifically #000000 which is a valid color).
return $sanitized_color;
}