batch_items() public method

Bulk create, update and delete items.
public batch_items ( WP_REST_Request $request ) : array
$request WP_REST_Request Full details about the request.
return array Of WP_Error or WP_REST_Response.
 /**
  * Bulk create, update and delete items.
  *
  * @since  2.7.0
  * @param WP_REST_Request $request Full details about the request.
  * @return array Of WP_Error or WP_REST_Response.
  */
 public function batch_items($request)
 {
     $items = array_filter($request->get_params());
     $params = $request->get_url_params();
     $product_id = $params['product_id'];
     $body_params = array();
     foreach (array('update', 'create', 'delete') as $batch_type) {
         if (!empty($items[$batch_type])) {
             $injected_items = array();
             foreach ($items[$batch_type] as $item) {
                 $injected_items[] = array_merge(array('product_id' => $product_id), $item);
             }
             $body_params[$batch_type] = $injected_items;
         }
     }
     $request = new WP_REST_Request($request->get_method());
     $request->set_body_params($body_params);
     return parent::batch_items($request);
 }
 /**
  * Bulk create, update and delete items.
  *
  * @since  2.7.0
  * @param WP_REST_Request $request Full details about the request.
  * @return array Of WP_Error or WP_REST_Response.
  */
 public function batch_items($request)
 {
     // Get the request params.
     $items = array_filter($request->get_params());
     /*
      * Since our batch settings update is group-specific and matches based on the route,
      * we inject the URL parameters (containing group) into the batch items
      */
     if (!empty($items['update'])) {
         $to_update = array();
         foreach ($items['update'] as $item) {
             $to_update[] = array_merge($request->get_url_params(), $item);
         }
         $request = new WP_REST_Request($request->get_method());
         $request->set_body_params(array('update' => $to_update));
     }
     return parent::batch_items($request);
 }