wc_sanitize_coupon_code()
Sanitize a coupon code.
Coupon codes are plain text, but are stored as post titles with &, < and > encoded the same way wp_kses() did, so codes saved by earlier versions still match. Kses and the post title filters aren't used, so the result doesn't depend on the current user or on how wp_kses() parses HTML. Use the woocommerce_coupon_code filter to change codes.
Хуков нет.
Возвращает
string.
Использование
wc_sanitize_coupon_code( $value );
- $value(строка|null) (обязательный)
- Coupon code to format.
Заметки
| Смотрите: WC_Formatting_Functions_Test::test_wc_sanitize_coupon_code |
| Смотрите: WC_Cart_Test::test_coupon_codes_with_special_characters |
Список изменений
| С версии 3.6.0 | Введена. |
| С версии 10.0.0 | Decode HTML entities here instead of via woocommerce_coupon_code filter. |
| С версии 11.3.0 | Encode special characters without kses or the post title filters, so the result no longer depends on the current user. |
Код wc_sanitize_coupon_code() wc sanitize coupon code WC 11.3.0
function wc_sanitize_coupon_code( $value ) {
if ( null === $value ) {
return '';
}
$value = html_entity_decode( $value, ENT_COMPAT, get_bloginfo( 'charset' ) );
$value = trim( wp_kses_no_null( $value, array( 'slash_zero' => 'keep' ) ) );
return str_replace( array( '<', '>' ), array( '<', '>' ), wp_kses_normalize_entities( $value ) );
}