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 #
Name | Type | Visibility | Usage | Description |
---|---|---|---|---|
$routes | array | private | static | Stores 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
Name | Type | Default | Description |
---|---|---|---|
$namespace | string | The namespace for the route (e.g., “v1”). | |
$route | string | The route pattern (e.g., “/example”). | |
$args | array | [] | Configuration options including methods, permissions, and callback. |
handleRequest #
Processes incoming requests and matches them to the registered routes.
Returns: void
Visibility: public
Usage: static
Name | Type | Default | Description |
---|---|---|---|
$method | string | The HTTP method of the request (e.g., GET, POST). | |
$uri | string | The 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
Name | Type | Default | Description |
---|---|---|---|
$args | array | Configuration options for the route. | |
$method | string | The HTTP method of the request. | |
$uri | string | The URI of the request. | |
$matches | array | Route parameters extracted from the URI. |
sendResponse #
Sends a WP_REST_Response
to the client.
Returns: void
Visibility: private
Usage: static
Name | Type | Default | Description |
---|---|---|---|
$response | WP_REST_Response | The 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
Name | Type | Default | Description |
---|---|---|---|
$message | string | A message describing the response. | |
$data | array|object | [] | Data to include in the response. |
$status_code | int | 200 | The HTTP status code of the response. |
$additional_errors | array | [] | Additional error information. |
$status_message | string | A human-readable status message. |
getHeaders #
Extracts HTTP headers from the server variables and returns them as an array.
Returns: array
Visibility: private
Usage: static
Name | Type | Default | Description |
---|---|---|---|
$server | array | An array of server variables from $_SERVER . |