From 5ab8e085ad3aefb912676738dda1fed234a23ec3 Mon Sep 17 00:00:00 2001 From: Max Rice Date: Thu, 14 Nov 2013 13:56:05 -0500 Subject: [PATCH] Update /coupons/code endpoint Part of #4055 --- includes/api/class-wc-api-coupons.php | 5 +++-- includes/api/class-wc-api-server.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/api/class-wc-api-coupons.php b/includes/api/class-wc-api-coupons.php index e0ced4f188e..1e1dff93cd4 100644 --- a/includes/api/class-wc-api-coupons.php +++ b/includes/api/class-wc-api-coupons.php @@ -49,8 +49,8 @@ class WC_API_Coupons extends WC_API_Resource { array( array( $this, 'delete_coupon' ), WC_API_Server::DELETABLE ), ); - # GET /coupons/ TODO: should looking up coupon codes containing spaces or dashes be supported? OR all-digit coupon codes - $routes[ $this->base . '/(?P\w+)' ] = array( + # GET /coupons/code/ + $routes[ $this->base . '/code/(?P\w[\w\s\-]*)' ] = array( // note that coupon codes can contain spaces, dashes and underscores array( array( $this, 'get_coupon_by_code' ), WC_API_Server::READABLE ), ); @@ -152,6 +152,7 @@ class WC_API_Coupons extends WC_API_Resource { /** * Get the coupon for the given code * + * @since 2.1 * @param string $code the coupon code * @param string $fields fields to include in response * @return int|WP_Error diff --git a/includes/api/class-wc-api-server.php b/includes/api/class-wc-api-server.php index 7b557657c47..772b2675fc4 100644 --- a/includes/api/class-wc-api-server.php +++ b/includes/api/class-wc-api-server.php @@ -326,7 +326,7 @@ class WC_API_Server { if ( !( $supported & $method ) ) continue; - $match = preg_match( '@^' . $route . '$@i', $this->path, $args ); + $match = preg_match( '@^' . $route . '$@i', urldecode( $this->path ), $args ); if ( !$match ) continue;