WC_Post_Data::sanitize_coupon_code_on_save
Sanitize coupon codes with wc_sanitize_coupon_code() when coupons are saved, so they're stored the same way for every user.
Uses the title passed to wp_insert_post(), because WordPress has already run kses on $data for some users.
Method of the class: WC_Post_Data{}
No Hooks.
Returns
array.
Usage
$result = WC_Post_Data::sanitize_coupon_code_on_save( $data, $postarr, $unsanitized_postarr );
- $data(array) (required)
- An array of slashed, sanitized post data.
- $postarr(array) (required)
- An array of sanitized post data.
- $unsanitized_postarr(array) (required)
- An array of slashed post data as passed to wp_insert_post().
Changelog
| Since 11.3.0 | Introduced. |
WC_Post_Data::sanitize_coupon_code_on_save() WC Post Data::sanitize coupon code on save code WC 11.3.0
public static function sanitize_coupon_code_on_save( $data, $postarr, $unsanitized_postarr ) {
global $wpdb;
if ( ! is_array( $data ) || 'shop_coupon' !== ( $data['post_type'] ?? '' ) ) {
return $data;
}
$title = wc_sanitize_coupon_code( wp_unslash( $unsanitized_postarr['post_title'] ?? $data['post_title'] ) );
// Like wp_insert_post(), encode emoji when the column can't store them.
if ( in_array( $wpdb->get_col_charset( $wpdb->posts, 'post_title' ), array( 'utf8', 'utf8mb3' ), true ) ) {
$title = wp_encode_emoji( $title );
}
$data['post_title'] = wp_slash( $title );
return $data;
}