Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks

Cover::validate_and_sanitize_color │ private │ WC 1.0

Validate and sanitize a color value, returning empty string for invalid colors.

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

Хуков нет.

Возвращает

string. Sanitized color or empty string if invalid.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->validate_and_sanitize_color( $color ): string;
$color(строка) (обязательный)
The color value to validate and sanitize.

Код Cover::validate_and_sanitize_color() WC 11.2.2

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;
}