From 1137782c6a6acc8666977b60e268ad4694ec19d0 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 24 Jul 2018 15:56:46 -0300 Subject: [PATCH] Improved links --- .../class-wc-rest-product-reviews-controller.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/includes/api/class-wc-rest-product-reviews-controller.php b/includes/api/class-wc-rest-product-reviews-controller.php index 2e453214eff..7ee75b0329f 100644 --- a/includes/api/class-wc-rest-product-reviews-controller.php +++ b/includes/api/class-wc-rest-product-reviews-controller.php @@ -432,11 +432,21 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller { 'collection' => array( 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), ), - 'product' => array( - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $review->comment_post_ID ) ), - ), ); + if ( 0 !== (int) $review->comment_post_ID ) { + $links['up'] = array( + 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $review->comment_post_ID ) ), + ); + } + + if ( 0 !== (int) $review->user_id ) { + $links['reviewer'] = array( + 'href' => rest_url( 'wp/v2/users/' . $review->user_id ), + 'embeddable' => true, + ); + } + return $links; }