Request a Demo
  • Platform
    • Donations
    • Campaigns
    • Events
    • eCards
    • CRM
  • Features
  • Integrations
  • Resources
    • Docs
    • Product updates
    • Changelog
  • Company
  • Platform
    • Donations
    • Campaigns
    • Events
    • eCards
    • CRM
  • Features
  • Integrations
  • Resources
    • Docs
    • Product updates
    • Changelog
  • Company
Request a Demo

Classes

  • Helpers/AdminMenuHelper
  • Helpers/API
  • Helpers/Helper
View Categories

Helpers/API

1 min read

Namespace #

LevCharity\Helpers\API

Overview #

This class provides a framework for registering and handling custom API routes in the LevCharity namespace. It allows defining routes, managing request permissions, and generating responses using the WordPress REST API infrastructure.


Properties #

NameTypeVisibilityUsageDescription
$routesarrayprivatestaticStores registered API routes and their associated metadata.

Methods #

route #

Registers a new API route with a namespace, route pattern, and configuration arguments.

Returns: void

Visibility: public

Usage: static

NameTypeDefaultDescription
$namespacestringThe namespace for the route (e.g., “v1”).
$routestringThe route pattern (e.g., “/example”).
$argsarray[]Configuration options including methods, permissions, and callback.

handleRequest #

Processes incoming requests and matches them to the registered routes.

Returns: void

Visibility: public

Usage: static

NameTypeDefaultDescription
$methodstringThe HTTP method of the request (e.g., GET, POST).
$uristringThe URI of the request.

processRequest #

Processes a matched request by creating a WP_REST_Request, validating permissions, and invoking the specified callback.

Returns: void

Visibility: private

Usage: static

NameTypeDefaultDescription
$argsarrayConfiguration options for the route.
$methodstringThe HTTP method of the request.
$uristringThe URI of the request.
$matchesarrayRoute parameters extracted from the URI.

sendResponse #

Sends a WP_REST_Response to the client.

Returns: void

Visibility: private

Usage: static

NameTypeDefaultDescription
$responseWP_REST_ResponseThe response object to be sent.

response #

Creates a standardized response object with a message, data, and status code.

Returns: WP_REST_Response

Visibility: public

Usage: static

NameTypeDefaultDescription
$messagestringA message describing the response.
$dataarray|object[]Data to include in the response.
$status_codeint200The HTTP status code of the response.
$additional_errorsarray[]Additional error information.
$status_messagestringA human-readable status message.

getHeaders #

Extracts HTTP headers from the server variables and returns them as an array.

Returns: array

Visibility: private

Usage: static

NameTypeDefaultDescription
$serverarrayAn array of server variables from $_SERVER.

Was this article helpful?
Still stuck? How can we help?

How can we help?

Updated on March 26, 2025
Helpers/AdminMenuHelperHelpers/Helper
Table of Contents
  • Namespace
  • Overview
  • Properties
  • Methods
    • route
    • handleRequest
    • processRequest
    • sendResponse
    • response
    • getHeaders
Join our newsletter

Add your email to stay up to date on features and new releases:

loader

  • Docs
  • Changelog
  • Privacy Policy
  • Terms of Service
  • Cookies Settings
  • Docs
  • Changelog
  • Privacy Policy
  • Terms of Service
  • Cookies Settings