Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



sanitize_hex_color_no_hash ›

Seit3.4.0
Veraltetn/v
sanitize_hex_color_no_hash ( $color )
Parameter:
  • (string) $color
    Erforderlich: Ja
Gibt zurück:
  • (string|null)
Definiert in:
Codex:

Sanitizes a hex color without a hash. Use sanitize_hex_color() when possible.

Saving hex colors without a hash puts the burden of adding the hash on the UI, which makes it difficult to use or upgrade to other color types such as rgba, hsl, rgb, and html color names.

Returns either '', a 3 or 6 digit hex color (without a #), or null.



Quellcode

function sanitize_hex_color_no_hash( $color ) {
	$color = ltrim( $color, '#' );

	if ( '' === $color ) {
		return '';
	}

	return sanitize_hex_color( '#' . $color ) ? $color : null;
}