formService = $formService; $this->fieldService = $fieldService; $this->notificationService = $notificationService; $this->confirmationService = $confirmationService; } /** * Delete forms by IDs * * @param WP_REST_Request $data * * @return WP_REST_Response * * @throws InvalidArgumentException * @throws NotFoundException * @throws ForbiddenException * */ public function handle(WP_REST_Request $data): WP_REST_Response { // Verify the nonce Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); // Check if the form IDs are provided if (empty($data->get_params())) { throw new InvalidArgumentException('Invalid request data.'); } $ids = Sanitizer::sanitizeIds($data->get_param('ids')) ; foreach ($ids as $id) { $this->formService->deleteForm($id); $this->fieldService->deleteFieldsByFormId($id); $this->notificationService->deleteNotificationsByFormId($id); $this->confirmationService->deleteConfirmationsByFormId($id); } return new WP_REST_Response( [ 'message' => 'Successfully deleted forms.', 'data' => [], ], 200 ); } }