Add links to coupons responses

This commit is contained in:
Claudio Sanches 2016-03-15 16:53:51 -03:00
parent 218390071c
commit 3b22acb2b1
1 changed files with 21 additions and 0 deletions

View File

@ -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.
*