Un motore di ricerca WordPress per sviluppatori e autori di temi



sanitize_hex_color ›

Da3.4.0
Deprecaton/a
sanitize_hex_color ( $color )
Parametri:
  • (string) $color
    Richiesto:
Ritorna:
  • (string|void)
Definito a:
Codex:

Sanitizes a hex color.

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



Sorgenti

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;
	}
}