Automattic\WooCommerce\Internal\ProductCustoms
CustomsDataValidator::normalize_description
Normalizes a plain text customs description of up to thirty-five Unicode code points. Only letters, digits, spaces, punctuation and printable ASCII symbols are allowed, so emoji (including keycap and variation-selector sequences) and symbols such as ™ are rejected. Angle brackets are rejected rather than stripped as markup, so text such as "Size<M shirt" isn't silently cut.
Метод класса: CustomsDataValidator{}
Хуков нет.
Возвращает
string|null.
Использование
$result = CustomsDataValidator::normalize_description( $value ): ?string;
- $value(разное) (обязательный)
- Plain text description, or null to clear it.
Список изменений
| С версии 11.3.0 | Введена. |
Код CustomsDataValidator::normalize_description() CustomsDataValidator::normalize description WC 11.3.0
public static function normalize_description( $value ): ?string {
if ( null === $value || '' === $value ) {
return null;
}
if ( is_string( $value ) && '' !== wp_check_invalid_utf8( $value ) ) {
$text = trim( (string) preg_replace( '/[\r\n\t ]+/', ' ', $value ) );
if ( '' === $text ) {
return null;
}
if ( mb_strlen( $text ) <= 35 && ! preg_match( '/[<>]|[^\x20-\x7E\p{L}\p{Mn}\p{Mc}\p{N}\p{P}\s]|[\x{FE00}-\x{FE0F}\x{E0100}-\x{E01EF}]/u', $text ) ) {
return $text;
}
}
throw new WC_Data_Exception(
'woocommerce_product_invalid_customs_description',
__( 'The customs description must be plain text with no more than 35 characters, without emoji or special symbols.', 'woocommerce' ), // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Escaped when output.
400
);
}