Traits

HasRestRoutes

v1.0.0

Adds registerRoute, registerGetRoute, and registerPostRoute helpers delegated to the centralized RestRouter.

Use Trait

use Meteorack\Sdk\RuntimeWp\Traits\HasRestRoutes;

How To Use It

  • AbstractModule already mixes this in, so call the helpers from inside your module instead of wiring raw register_rest_route calls everywhere.
  • Use the GET and POST helpers for common cases and pass a custom permission callback only when the default logged-in check is not enough.

Helpers

protected function registerRoute(string $route, array $args): void

Registers a raw route definition with the centralized REST router.

protected function registerGetRoute(string $route, callable $callback, callable $permissionCallback = null): void

Registers a GET route with an optional permission callback.

protected function registerPostRoute(string $route, callable $callback, callable $permissionCallback = null): void

Registers a POST route with an optional permission callback.

Example

bootstrap.php
public function onSdkReady(SdkContext $ctx): void
{
    parent::onSdkReady($ctx);

    $this->registerGetRoute('/reports/stats', [$this, 'getStats']);
    $this->registerPostRoute('/reports/resync', [$this, 'triggerResync'], function (): bool {
        return current_user_can('manage_options');
    });
}