templateService = $templateService; } /** * @param WP_REST_Request> $data * @return WP_REST_Response * @throws ForbiddenException * @throws InvalidArgumentException */ public function handle(WP_REST_Request $data): WP_REST_Response { // Verify the nonce Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); // TODO Add validation for template_id with Sanitizer //$templateId = Sanitizer::sanitizeText($data->get_param('id')); $templateId = sanitize_text_field($data->get_param('id') ?? ''); if (empty($templateId)) { throw new InvalidArgumentException( BackendStrings::getTemplateStrings()['required_template_id'] ); } $template = $this->templateService->getTemplateById($templateId); if (!$template) { throw new InvalidArgumentException( BackendStrings::getTemplateStrings()['template_not_found'] ); } return new WP_REST_Response([ 'success' => true, 'data' => $template ], 200); } }