From 0463516020c15d791f98769a2bb1748d41f83b68 Mon Sep 17 00:00:00 2001 From: Gerhard Date: Thu, 6 Mar 2014 10:08:27 +0200 Subject: [PATCH] Remove duplicate coupon type check --- includes/api/class-wc-api-coupons.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/includes/api/class-wc-api-coupons.php b/includes/api/class-wc-api-coupons.php index ec2ca676c59..0cd10922741 100644 --- a/includes/api/class-wc-api-coupons.php +++ b/includes/api/class-wc-api-coupons.php @@ -201,11 +201,6 @@ class WC_API_Coupons extends WC_API_Resource { return new WP_Error( 'woocommerce_api_missing_coupon_code', sprintf( __( 'Missing parameter %s' ), 'code' ), array( 'status' => 400 ) ); } - // Validate coupon types - if ( ! in_array( wc_clean( $data['type'] ), array_keys( wc_get_coupon_types() ) ) ) { - return new WP_Error( 'woocommerce_api_invalid_coupon_type', sprintf( __( 'Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce' ), implode( ', ', array_keys( wc_get_coupon_types() ) ) ), array( 'status' => 400 ) ); - } - $coupon_code = apply_filters( 'woocommerce_coupon_code', $data['code'] ); // Check for duplicate coupon codes @@ -243,8 +238,9 @@ class WC_API_Coupons extends WC_API_Resource { $coupon_data = wp_parse_args( $data, $defaults ); - if ( ! in_array( $coupon_data['type'], array_keys( wc_get_coupon_types() ) ) ) { - return new WP_Error( 'woocommerce_api_invalid_coupon_type', __( 'Invalid coupon type', 'woocommerce'), array( 'status' => 400 ) ); + // Validate coupon types + if ( ! in_array( wc_clean( $data['type'] ), array_keys( wc_get_coupon_types() ) ) ) { + return new WP_Error( 'woocommerce_api_invalid_coupon_type', sprintf( __( 'Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce' ), implode( ', ', array_keys( wc_get_coupon_types() ) ) ), array( 'status' => 400 ) ); } $new_coupon = array( @@ -329,8 +325,9 @@ class WC_API_Coupons extends WC_API_Resource { } if ( isset( $data['type'] ) ) { - if ( ! in_array( $data['type'], array_keys( wc_get_coupon_types() ) ) ) { - return new WP_Error( 'woocommerce_api_invalid_coupon_type', __( 'Invalid coupon type', 'woocommerce'), array( 'status' => 400 ) ); + // Validate coupon types + if ( ! in_array( wc_clean( $data['type'] ), array_keys( wc_get_coupon_types() ) ) ) { + return new WP_Error( 'woocommerce_api_invalid_coupon_type', sprintf( __( 'Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce' ), implode( ', ', array_keys( wc_get_coupon_types() ) ) ), array( 'status' => 400 ) ); } update_post_meta( $id, 'discount_type', $data['type'] ); }