Do not allow manipulate variations on products endpoint

This commit is contained in:
Claudio Sanches 2017-02-16 22:40:37 -02:00
parent 63cb7e7c27
commit 55977d03f3
1 changed files with 8 additions and 0 deletions

View File

@ -652,6 +652,10 @@ class WC_REST_Products_Controller extends WC_REST_CRUD_Controller {
$product = new WC_Product_Simple(); $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. // Post title.
if ( isset( $request['name'] ) ) { if ( isset( $request['name'] ) ) {
$product->set_name( wp_filter_post_kses( $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 ) ); 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' ) ); $supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) );
/** /**