From 4b90c12db1815c57b62bf64194638a89944bf05a Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 25 Oct 2017 20:40:44 -0200 Subject: [PATCH 1/2] Fixed coding standards. Still missing fix the file name, but I'll leave it for 3.3 --- ...s-wc-rest-product-categories-controller.php | 9 +++++---- ...s-wc-rest-product-categories-controller.php | 18 +++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/includes/api/class-wc-rest-product-categories-controller.php b/includes/api/class-wc-rest-product-categories-controller.php index 599e2561340..ce5ac30b4c3 100644 --- a/includes/api/class-wc-rest-product-categories-controller.php +++ b/includes/api/class-wc-rest-product-categories-controller.php @@ -32,9 +32,9 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Product_Categories_V /** * Prepare a single product category output for response. * - * @param WP_Term $item Term object. - * @param WP_REST_Request $request - * @return WP_REST_Response $response + * @param WP_Term $item Term object. + * @param WP_REST_Request $request Request instance. + * @return WP_REST_Response */ public function prepare_item_for_response( $item, $request ) { // Get category display type. @@ -56,7 +56,8 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Product_Categories_V ); // Get category image. - if ( $image_id = get_woocommerce_term_meta( $item->term_id, 'thumbnail_id' ) ) { + $image_id = get_woocommerce_term_meta( $item->term_id, 'thumbnail_id' ); + if ( $image_id ) { $attachment = get_post( $image_id ); $data['image'] = array( diff --git a/includes/api/v1/class-wc-rest-product-categories-controller.php b/includes/api/v1/class-wc-rest-product-categories-controller.php index 182dc482bb2..9052cccd370 100644 --- a/includes/api/v1/class-wc-rest-product-categories-controller.php +++ b/includes/api/v1/class-wc-rest-product-categories-controller.php @@ -46,9 +46,9 @@ class WC_REST_Product_Categories_V1_Controller extends WC_REST_Terms_Controller /** * Prepare a single product category output for response. * - * @param WP_Term $item Term object. - * @param WP_REST_Request $request - * @return WP_REST_Response $response + * @param WP_Term $item Term object. + * @param WP_REST_Request $request Request instance. + * @return WP_REST_Response */ public function prepare_item_for_response( $item, $request ) { // Get category display type. @@ -70,7 +70,8 @@ class WC_REST_Product_Categories_V1_Controller extends WC_REST_Terms_Controller ); // Get category image. - if ( $image_id = get_woocommerce_term_meta( $item->term_id, 'thumbnail_id' ) ) { + $image_id = get_woocommerce_term_meta( $item->term_id, 'thumbnail_id' ); + if ( $image_id ) { $attachment = get_post( $image_id ); $data['image'] = array( @@ -106,8 +107,8 @@ class WC_REST_Product_Categories_V1_Controller extends WC_REST_Terms_Controller /** * Update term meta fields. * - * @param WP_Term $term - * @param WP_REST_Request $request + * @param WP_Term $term Term object. + * @param WP_REST_Request $request Request instance. * @return bool|WP_Error */ protected function update_term_meta_fields( $term, $request ) { @@ -145,7 +146,10 @@ class WC_REST_Product_Categories_V1_Controller extends WC_REST_Terms_Controller // Set the image title. if ( ! empty( $request['image']['title'] ) ) { - wp_update_post( array( 'ID' => $image_id, 'post_title' => wc_clean( $request['image']['title'] ) ) ); + wp_update_post( array( + 'ID' => $image_id, + 'post_title' => wc_clean( $request['image']['title'] ), + ) ); } } else { delete_woocommerce_term_meta( $id, 'thumbnail_id' ); From 6e9ad75be5a026cebebd092ab564fe27e859d82f Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 25 Oct 2017 20:41:31 -0200 Subject: [PATCH 2/2] Category image is a single object --- includes/api/class-wc-rest-product-categories-controller.php | 2 +- includes/api/v1/class-wc-rest-product-categories-controller.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/api/class-wc-rest-product-categories-controller.php b/includes/api/class-wc-rest-product-categories-controller.php index ce5ac30b4c3..762bee926f8 100644 --- a/includes/api/class-wc-rest-product-categories-controller.php +++ b/includes/api/class-wc-rest-product-categories-controller.php @@ -50,7 +50,7 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Product_Categories_V 'parent' => (int) $item->parent, 'description' => $item->description, 'display' => $display_type ? $display_type : 'default', - 'image' => array(), + 'image' => null, 'menu_order' => (int) $menu_order, 'count' => (int) $item->count, ); diff --git a/includes/api/v1/class-wc-rest-product-categories-controller.php b/includes/api/v1/class-wc-rest-product-categories-controller.php index 9052cccd370..c5bfee7ff45 100644 --- a/includes/api/v1/class-wc-rest-product-categories-controller.php +++ b/includes/api/v1/class-wc-rest-product-categories-controller.php @@ -64,7 +64,7 @@ class WC_REST_Product_Categories_V1_Controller extends WC_REST_Terms_Controller 'parent' => (int) $item->parent, 'description' => $item->description, 'display' => $display_type ? $display_type : 'default', - 'image' => array(), + 'image' => null, 'menu_order' => (int) $menu_order, 'count' => (int) $item->count, );