rest_parse_hex_color() WordPress Function

The rest_parse_hex_color() function is used to parse a hex color value and return a corresponding RGB value. This function is useful for converting a hex color value into a format that can be used by CSS or other color-related functions.

rest_parse_hex_color( string $color ) #

Parses a 3 or 6 digit hex color (with #).


Parameters

$color

(string)(Required)3 or 6 digit hex color (with #).


Top ↑

Return

(string|false)


Top ↑

Source

File: wp-includes/rest-api.php

function rest_parse_hex_color( $color ) {
	$regex = '|^#([A-Fa-f0-9]{3}){1,2}$|';
	if ( ! preg_match( $regex, $color, $matches ) ) {
		return false;
	}

	return $color;
}


Top ↑

Changelog

Changelog
VersionDescription
5.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More