Parses a 3 or 6 digit hex color (with #).
Parameters
$color
stringrequired- 3 or 6 digit hex color (with #).
Source
function rest_parse_hex_color( $color ) {
$regex = '|^#([A-Fa-f0-9]{3}){1,2}$|';
if ( ! preg_match( $regex, $color, $matches ) ) {
return false;
}
return $color;
}
Changelog
Version | Description |
---|---|
5.4.0 | Introduced. |
I wonder why this function was added, when an older function does the same thing.
https://developer.wordpress.org/reference/functions/sanitize_hex_color/