Docs
Functions

kizlo_register_route

Register an admin-only REST endpoint under the Kizlo namespace.

kizlo_register_route registers a REST endpoint under Kizlo's namespace (kizlo/v1). It is admin-only: Kizlo attaches a permission check requiring the manage_options capability, so the route is reachable only by authenticated administrators. A permission_callback of your own is not supported. Passing one is reported and discarded, and the admin-only check is attached in its place. Call it from your plugin. It's a global, so no import is needed.

method accepts one HTTP method string. Arrays and the plural methods key are rejected. When a declaration opts into introspection with id, one operation becomes one generated client method, camelized on the way out, so bulk_delete is called as bulkDelete(). Register a separately named operation for each method when one path supports several methods.

Parameters

kizlo_register_route(array $args): void
KeyTypeDescription
routestringRequired. Route pattern, e.g. /forms/(?P<id>\d+). Build one from :param syntax with kizlo_route.
methodstringOne HTTP method. Use a single-method WP_REST_Server constant such as READABLE or CREATABLE.
callbackcallableRequired. Handler receiving a WP_REST_Request, returning a WP_REST_Response or WP_Error.
argsarrayOptional per-parameter validation/sanitization rules, passed through to register_rest_route. Rejected alongside id, which declares its parameters in input.

route and callback are both required. Omitting either triggers _doing_it_wrong, and the route is skipped. The callback is wrapped so a thrown InvalidArgumentException becomes a 400 invalid_param response automatically.

Introspection contract

Set id to publish the route in GET /kizlo/v1/introspect:

KeyTypeDescription
idstringAPI ID that groups related operations.
operationstringOperation name in lowercase snake_case, such as list, retrieve, or bulk_delete.
inputarrayRequest schema. Top-level properties become route arguments.
errorsstring[]Handler-specific WordPress error codes the operation can return.
responsesarrayStatus-keyed response contracts for success and error responses.
summarystringOptional short operation summary.
descriptionstringOptional operation description.
deprecatedboolOptional deprecation marker.

errors belongs to the operation, not an individual response. Declare each handler-specific code once as a non-empty string. Kizlo sorts the published list and adds the shared authentication, permission, argument-validation, and callback-wrapper codes automatically. An operation with errors must include a non-2xx JSON response whose body is kizlo.error.

kizlo_register_route([
    'id'        => 'orders',
    'operation' => 'retrieve',
    'route'     => kizlo_route('/orders/:id'),
    'method'    => WP_REST_Server::READABLE,
    'callback'  => [$controller, 'retrieve'],
    'input'     => [
        'type'       => 'object',
        'properties' => [
            'id' => ['type' => 'integer', 'required' => true],
        ],
    ],
    'errors'    => ['order_not_found'],
    'responses' => [
        '200' => ['body' => ['$ref' => 'orders.order']],
        '404' => ['body' => ['$ref' => 'kizlo.error']],
    ],
]);

Returns

void. The route is registered on rest_api_init, served at /wp-json/kizlo/v1<route>.

Examples

wp-content/plugins/your-plugin/forms.php
kizlo_register_route([
    'route'    => '/forms/(?P<id>\d+)',
    'method'   => WP_REST_Server::READABLE,
    'callback' => function (WP_REST_Request $request): WP_REST_Response {
        return new WP_REST_Response(['id' => $request->get_param('id')]);
    },
]);

Route patterns

Two helpers build and match :param-style route patterns instead of hand-writing regex.

kizlo_route

kizlo_route(string $path): string

Converts each :name placeholder into a named capture group matching [a-zA-Z0-9_.%+-]+:

kizlo_route('/cf7/submit/:form_id');
// → '/cf7/submit/(?P<form_id>[a-zA-Z0-9_.%+-]+)'

kizlo_register_route([
    'route'    => kizlo_route('/forms/:id/fields/:field_id'),
    'method'   => WP_REST_Server::READABLE,
    'callback' => $handler,
]);

kizlo_route_match

kizlo_route_match(string $route, WP_REST_Request $request): bool

Returns true when a request's route matches a :param pattern, the same matching kizlo_register_route_interceptor uses internally.

if (kizlo_route_match('/forms/:id', $request)) {
    // this request targets a single form
}

On this page