Configuration

Configuration options for WPZylos Routing.

Service Provider Options

The RoutingServiceProvider automatically loads route files from standard locations.

Route File Locations

Route TypeDefault Location
Frontendroutes/web.php
REST APIroutes/api.php
AJAXroutes/ajax.php

REST API Namespace

The REST API namespace is derived from your plugin context:

// Plugin slug: "my-plugin"
// API version: "v1"
// Namespace: "my-plugin/v1"
// Endpoint: /wp-json/my-plugin/v1/...

Container Bindings

The service provider registers these bindings:

BindingClassDescription
Router::classRouterFrontend router
'router'RouterAlias
RestRouter::classRestRouterREST API router
'rest'RestRouterAlias
AjaxRouter::classAjaxRouterAJAX router
'ajax'AjaxRouterAlias
RouteDispatcher::classRouteDispatcherFrontend dispatcher
RestDispatcher::classRestDispatcherREST dispatcher
WPAdapter::classWPAdapterWordPress rewrite adapter

WordPress Hooks

Routes are dispatched via these hooks:

RouterHookPriority
Frontendtemplate_redirect1
REST APIrest_api_init10
AJAXinit10

Middleware Configuration

Middleware classes must implement a handle method:

public function handle($request, callable $next): mixed
{
    // Before
    $response = $next($request);
    // After
    return $response;
}

Nonce Configuration

AJAX nonce actions are prefixed with the plugin prefix:

// Plugin prefix: "myplugin_"
// Action: "save_settings"
// Nonce action: "myplugin_save_settings"

Rewrite Rules

Frontend routes automatically register WordPress rewrite rules on activation:

// Pattern: /products/{id}
// Rewrite: ^products/([^/]+)/?$
// Target: index.php?myplugin_route=/products/{id}

Flush rewrite rules after route changes:

WPAdapter::flush();