formService = $formService; $this->fieldService = $fieldService; } /** * @param WP_REST_Request $data * * @return WP_REST_Response * * @throws NotFoundException * @throws InvalidArgumentException * @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 ID is provided if (empty($data->get_param('id'))) { throw new InvalidArgumentException('Form ID is required.'); } // Sanitize the input data $formId = Sanitizer::sanitizeId($data->get_param('id')); $this->formService->deleteForm($formId); $this->fieldService->deleteFieldsByFormId($formId); return new WP_REST_Response([ 'message' => 'Successfully deleted form.', 'data' => [] ], 200); } }