rest_parse_hex_color

The timeline below displays how wordpress function rest_parse_hex_color has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

/**
 * Parses a 3 or 6 digit hex color (with #).
 *
 * @since 5.4.0
 *
 * @param string $color 3 or 6 digit hex color (with #).
 * @return string|false
 */
function rest_parse_hex_color($color)
{
    $regex = '|^#([A-Fa-f0-9]{3}){1,2}$|';
    if (!preg_match($regex, $color, $matches)) {
        return false;
    }
    return $color;
}