wc_sanitize_coupon_code()WC 3.6.0

Sanitize a coupon code.

Uses sanitize_post_field since coupon codes are stored as post_titles - the sanitization and escaping must match.

Due to the unfiltered_html captability that some (admin) users have, we need to account for slashes.

No Hooks.

Return

String.

Usage

wc_sanitize_coupon_code( $value );
$value(string) (required)
Coupon code to format.

Changelog

Since 3.6.0 Introduced.

wc_sanitize_coupon_code() code WC 8.7.0

function wc_sanitize_coupon_code( $value ) {
	$value = wp_kses( sanitize_post_field( 'post_title', $value ?? '', 0, 'db' ), 'entities' );
	return current_user_can( 'unfiltered_html' ) ? $value : stripslashes( $value );
}