WC_REST_Product_Variations_V2_Controller::update_item_permissions_checkpublicWC 1.0

Check if a given request has access to update an item.

Method of the class: WC_REST_Product_Variations_V2_Controller{}

No Hooks.

Returns

WP_Error|true|false.

Usage

$WC_REST_Product_Variations_V2_Controller = new WC_REST_Product_Variations_V2_Controller();
$WC_REST_Product_Variations_V2_Controller->update_item_permissions_check( $request );
$request(WP_REST_Request) (required)
Full details about the request.

WC_REST_Product_Variations_V2_Controller::update_item_permissions_check() code WC 10.3.6

public function update_item_permissions_check( $request ) {
	if ( ! $this->check_variation_parent( (int) $request['id'], (int) $request['product_id'] ) ) {
		return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	$object = $this->get_object( (int) $request['id'] );

	if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) {
		return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
	}

	return true;
}