root}{$this->endpoint()}", [ [ 'methods' => 'POST', 'callback' => [$this, 'handleRequestWithDonorIdCheck'], 'permission_callback' => function () { return DonorDashboardHelpers::isDonorLoggedIn(); }, ], 'args' => $this->args(), ] ); } /** * @since 2.26.0 add try/catch to handleRequest */ public function handleRequestWithDonorIdCheck(WP_REST_Request $request) { $donorId = $request->get_param('donor_id') !== null ? $request->get_param('donor_id') : give()->donorDashboard->getId(); // Check that the provided donor ID is valid if (!Give()->donors->get_donor_by('id', $donorId)) { Log::error( esc_html__('An error occurred while validating donor ID on request.', 'give'), [ 'source' => 'Donor Dashboard', 'Donor ID' => give()->donorDashboard->getId(), 'Current User ID' => get_current_user_id(), 'Email Access Token' => give()->email_access->token_email, 'Session Email' => give()->session->get('give_email'), 'Session Expiration' => give()->session->get_session_expiration(), 'Error' => __('Donor ID could not be validated for request.', 'give'), ] ); return new WP_REST_Response( [ 'status' => 400, 'response' => 'invalid_donor_id', 'body_response' => [ 'message' => html_entity_decode( esc_html__( 'An error occurred while retrieving your donation records. Contact a site administrator and have them search the logs at Donations > Tools > Logs for a more specific cause of the problem.', 'give' ) ), ], ] ); } try { $response = $this->handleRequest($request); return rest_ensure_response($response ?? []); } catch (Exception $exception) { $error = new WP_Error('error', $exception->getMessage()); return rest_ensure_response($error); } } }