API Reference

Class and method documentation for WPZylos Routing.

Router

Frontend routing with WordPress rewrite integration.

Methods

MethodDescription
get(string $pattern, callable|array $handler): RouteRegister GET route
post(string $pattern, callable|array $handler): RouteRegister POST route
put(string $pattern, callable|array $handler): RouteRegister PUT route
patch(string $pattern, callable|array $handler): RouteRegister PATCH route
delete(string $pattern, callable|array $handler): RouteRegister DELETE route
match(array $methods, string $pattern, callable|array $handler): RouteRegister route for multiple methods
any(string $pattern, callable|array $handler): RouteRegister route for all methods
group(array $attributes, callable $callback): staticCreate route group
url(string $name, array $params = []): stringGenerate URL from named route
dispatch(string $method, string $uri): ?MatchedRouteDispatch a request
getRoute(string $name): ?RouteGet a route by name
registerNamedRoute(Route $route): voidRegister a named route
getRoutes(): Route[]Get all registered routes

Route

Individual route definition.

Methods

MethodDescription
name(string $name): staticSet route name
middleware(string|array $middleware): staticAdd middleware
where(string $key, string $pattern): staticAdd parameter constraint
getName(): ?stringGet route name
getMethod(): stringGet HTTP method
getPattern(): stringGet URL pattern
getHandler(): callable|arrayGet route handler
getMiddleware(): arrayGet middleware stack
getConstraints(): arrayGet parameter constraints

RestRouter

REST API routing for /wp-json/ endpoints.

Constructor

new RestRouter(string $namespace, string $version = 'v1')

Methods

MethodDescription
get(string $pattern, callable|array $handler): RestRouteRegister GET endpoint
post(string $pattern, callable|array $handler): RestRouteRegister POST endpoint
put(string $pattern, callable|array $handler): RestRouteRegister PUT endpoint
patch(string $pattern, callable|array $handler): RestRouteRegister PATCH endpoint
delete(string $pattern, callable|array $handler): RestRouteRegister DELETE endpoint
match(array $methods, string $pattern, callable|array $handler): RestRouteRegister multi-method endpoint
group(array $attributes, callable $callback): staticCreate route group
resource(string $name, string $controller, array $only = []): staticCreate resource routes
getRoutes(): RestRoute[]Get all registered routes
getNamespace(): stringGet REST namespace

RestRoute

REST API route definition.

Methods

MethodDescription
name(string $name): staticSet route name
middleware(string|array $middleware): staticAdd middleware
permission(string $capability): staticSet required capability
setPermissionCallback(callable $callback): staticSet custom permission callback
args(array $args): staticDefine argument schema
where(string $key, string $pattern): staticAdd parameter constraint
getWpMethod(): stringGet WP REST method constant
getWpPattern(): stringGet WP-formatted pattern
getPermission(): ?stringGet required capability
getPermissionCallback(): ?callableGet permission callback
getArgs(): arrayGet argument schema

AjaxRouter

WordPress AJAX action routing.

Constructor

new AjaxRouter(ContextInterface $context, ContainerInterface $container)

Methods

MethodDescription
public(string $action, callable|array $handler): AjaxRouteRegister public action
private(string $action, callable|array $handler): AjaxRouteRegister private action (login required)
group(array $attributes, callable $callback): staticCreate route group
url(string $action): stringGet AJAX URL for action
nonce(string $action): stringGenerate nonce for action
nonceField(string $action): stringGenerate nonce field HTML
getRoutes(): AjaxRoute[]Get all registered routes
register(): voidRegister all routes with WordPress

AjaxRoute

AJAX action definition.

Methods

MethodDescription
middleware(string|array $middleware): staticAdd middleware
nonce(string $action): staticSet custom nonce action
withoutNonce(): staticDisable nonce verification
isPublic(): boolCheck if route is public
shouldVerifyNonce(): boolCheck if nonce should be verified
getAction(): stringGet action name
getHandler(): callable|arrayGet route handler
getMiddleware(): arrayGet middleware stack
getNonceAction(): stringGet nonce action name

RouteDispatcher

Dispatches frontend routes on template_redirect.

Methods

MethodDescription
dispatch(): boolDispatch matching route, returns handled
shouldDispatch(): boolCheck if dispatch should run in context
registerHook(): voidRegister WordPress hook

RestDispatcher

Registers REST routes on rest_api_init.

Methods

MethodDescription
register(): voidRegister all routes with WordPress
registerHook(): voidRegister WordPress hook

WPAdapter

WordPress rewrite integration.

Methods

MethodDescription
registerRewriteRules(Route[] $routes): voidRegister rewrite rules
addQueryVars(array $vars): arrayAdd query variables
isPluginRoute(): boolCheck if current request matches
getMatchedPattern(): ?stringGet matched route pattern
static flush(): voidFlush rewrite rules

RoutingServiceProvider

Service provider for routing components.

Registered Services

BindingType
Router::classSingleton
'router'Alias
RestRouter::classSingleton
'rest'Alias
AjaxRouter::classSingleton
'ajax'Alias
RouteDispatcher::classSingleton
RestDispatcher::classSingleton
WPAdapter::classSingleton