formService = $formService; } /** * @param WP_REST_Request $data * * @return WP_REST_Response * * @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 data is provided if (empty($data->get_params())) { throw new InvalidArgumentException( BackendStrings::getExceptionStrings()['invalid_request_data'] ); } $formId = Sanitizer::sanitizeId($data->get_params()['id']); if ($formId <= 0) { throw new InvalidArgumentException( BackendStrings::getExceptionStrings()['invalid_form_id'] ); } $value = (bool)($data->get_params()['value']); // Update the specific attribute in the database $this->formService->updateFormStarred($formId, $value); return new WP_REST_Response([ 'message' => BackendStrings::getCommonStrings()['ok'], 'data' => [ 'id' => $formId, 'value' => $value, ] ], 200); } }