Skip to content

Endpoints Helper

Mattias edited this page Aug 1, 2021 · 1 revision

buildArray()

The buildArray function registers new api endpoints. addTheActions registers defined endpoints with buildArray.

buildArray(string $namespace, string $route, array $args)

Parameters

  • namespace (string) (Required)
  • route (string) (Required)
  • args (array) (Required) Array of options for the endpoint.

Example

endpoints()->buildArray('iroh', '/iroh-route', [
    'methods'             => 'POST',
    'callback'            => 'iroh_example_function',
    'permission_callback' => '__return_true',
])->buildArray('iroh', '/iroh-route-1', [
    'methods'             => 'GET',
    'callback'            => 'iroh_example_function',
    'permission_callback' => '__return_true',
])->addTheActions();

function iroh_example_function()
{
    return wp_send_json('iroh', 200);
}
Clone this wiki locally