From 3b22acb2b17ffb3fbcab0806014287babbe6d8b5 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 15 Mar 2016 16:53:51 -0300 Subject: [PATCH] Add links to coupons responses --- includes/api/wc-rest-coupons-controller.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/includes/api/wc-rest-coupons-controller.php b/includes/api/wc-rest-coupons-controller.php index 687eb4a109a..cd9a44b764a 100644 --- a/includes/api/wc-rest-coupons-controller.php +++ b/includes/api/wc-rest-coupons-controller.php @@ -144,6 +144,8 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller { // Wrap the data in a response object. $response = rest_ensure_response( $data ); + $response->add_links( $this->prepare_links( $post ) ); + /** * Filter the data for a response. * @@ -157,6 +159,25 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller { return apply_filters( 'woocommerce_rest_prepare_coupon', $response, $post, $request ); } + /** + * Prepare links for the request. + * + * @param WP_Post $post Customer object. + * @return array Links for the given post. + */ + protected function prepare_links( $post ) { + $links = array( + 'self' => array( + 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ), + ), + 'collection' => array( + 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), + ), + ); + + return $links; + } + /** * Prepare a single coupon for create or update. *