Switch language
wpseek on Twitter


A WordPress-centric search engine for devs and theme authors




sanitize_hex_color [ ]

sanitize_hex_color ( $color )
Parameters:
  • (string) $color
Returns:
  • (string|null)
Defined at:
Codex



Sanitizes a hex color.

Returns either '', a 3 or 6 digit hex color (with #), or null. For sanitizing values without a #, see sanitize_hex_color_no_hash().

Source

function sanitize_hex_color( $color ) {
	if ( '' === $color )
		return '';

	// 3 or 6 hex digits, or the empty string.
	if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) )
		return $color;

	return null;
}

Top Google Search Results

More ...

User discussions [ wordpress.org ]

User Note(s)