Configuration
Configuration options for WPZylos Routing.
Service Provider Options
The RoutingServiceProvider automatically loads route files from standard locations.
Route File Locations
| Route Type | Default Location |
|---|---|
| Frontend | routes/web.php |
| REST API | routes/api.php |
| AJAX | routes/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:
| Binding | Class | Description |
|---|---|---|
Router::class | Router | Frontend router |
'router' | Router | Alias |
RestRouter::class | RestRouter | REST API router |
'rest' | RestRouter | Alias |
AjaxRouter::class | AjaxRouter | AJAX router |
'ajax' | AjaxRouter | Alias |
RouteDispatcher::class | RouteDispatcher | Frontend dispatcher |
RestDispatcher::class | RestDispatcher | REST dispatcher |
WPAdapter::class | WPAdapter | WordPress rewrite adapter |
WordPress Hooks
Routes are dispatched via these hooks:
| Router | Hook | Priority |
|---|---|---|
| Frontend | template_redirect | 1 |
| REST API | rest_api_init | 10 |
| AJAX | init | 10 |
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();