sanitize_hex_color_no_hash()
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.
Хуков нет.
Возвращает
Строку|null. The sanitized hex color without the hash prefix, empty string if input is empty, or null if invalid.
Использование
sanitize_hex_color_no_hash( $color );
- $color(строка) (обязательный)
- The color value to sanitize. Can be with or without a #.
Список изменений
| С версии 3.4.0 | Введена. |
Код sanitize_hex_color_no_hash() sanitize hex color no hash WP 7.0.4
function sanitize_hex_color_no_hash( $color ) {
$color = ltrim( $color, '#' );
if ( '' === $color ) {
return '';
}
return sanitize_hex_color( '#' . $color ) ? $color : null;
}