Merge pull request #21696 from siananda/fix-21652

Prevent deleting default product category via REST API
This commit is contained in:
Claudiu Lodromanean 2018-11-02 08:09:21 -07:00 committed by GitHub
commit 4aad055e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -533,6 +533,14 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
}
$term = get_term( (int) $request['id'], $taxonomy );
// Get default category id.
$default_category_id = absint( get_option( 'default_product_cat', 0 ) );
// Prevent deleting the default product category.
if ( $default_category_id === (int) $request['id'] ) {
return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Default product category cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
}
$request->set_param( 'context', 'edit' );
$response = $this->prepare_item_for_response( $term, $request );