WordPress开发者和主题制作者的搜索引擎



sanitize_hex_color_no_hash ›

Since3.4.0
已弃用n/a
sanitize_hex_color_no_hash ( $color )
参数:
  • (string) $color
    Required: Yes
返回:
  • (string|null)
定义在:
文档:

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.



源码

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

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

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