sanitize_hex_color() │ WP 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().

Хуков нет.

Возвращает

string|null. The sanitized hex color, or null if invalid.

Использование

sanitize_hex_color( $color );
$color(строка) (обязательный)
.

Список изменений

С версии 3.4.0 Введена.

Код sanitize_hex_color() WP 7.1.4

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