sanitize_hex_color

函数


sanitize_hex_color ( $color )
参数
  • (string)
    $color
    Required:
返回值
  • (string|void)
定义位置
  • wp-includes/formatting.php
    , line 6061
引入
3.4.0
弃用

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().

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