Tribe__Validate::color()
Validates and sanitizes a HTML color codes, including hex, rgb, rgba, hsl and hsla.
Source
File: src/Tribe/Validate.php
public function color() {
if ( preg_match( '/^(#(?:[0-9a-f]{2}){2,4}|#[0-9a-f]{3}|(?:rgba?|hsla?)\((?:\d+%?(?:deg|rad|grad|turn)?(?:,|\s)+){2,3}[\s\/]*[\d\.]+%?\))$/i', $this->value ) ) {
$this->result->valid = true;
} else {
$this->result->valid = false;
$this->result->error = sprintf( esc_html__( '%s must be a valid HTML color code.', 'tribe-common' ), $this->label );
}
}
Changelog
| Version | Description |
|---|---|
| 5.0.0 | Introduced. |