From 55977d03f398f6a4d520f282c2c717dacd9c7375 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 16 Feb 2017 22:40:37 -0200 Subject: [PATCH] Do not allow manipulate variations on products endpoint --- includes/api/class-wc-rest-products-controller.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/api/class-wc-rest-products-controller.php b/includes/api/class-wc-rest-products-controller.php index 803680b77ed..f9624cf7bb9 100644 --- a/includes/api/class-wc-rest-products-controller.php +++ b/includes/api/class-wc-rest-products-controller.php @@ -652,6 +652,10 @@ class WC_REST_Products_Controller extends WC_REST_CRUD_Controller { $product = new WC_Product_Simple(); } + if ( 'variation' === $product->get_type() ) { + return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) ); + } + // Post title. if ( isset( $request['name'] ) ) { $product->set_name( wp_filter_post_kses( $request['name'] ) ); @@ -1234,6 +1238,10 @@ class WC_REST_Products_Controller extends WC_REST_CRUD_Controller { return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) ); } + if ( 'variation' === $object->get_type() ) { + return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) ); + } + $supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) ); /**