RestRouteMiddlewareInterface
in
Per-route middleware that wraps a single WordPress REST controller action.
The WP-REST-native counterpart of the framework's
RouteMiddlewareInterface: that contract
is HttpFoundation-native and composes with the admin
WpHttpKernel; this one speaks WP_REST_Request /
WP_REST_Response so it composes directly with the WpRestKernel
dispatch without a per-route HttpFoundation bridge, and a denial stays in the
product's REST envelope (e.g. RestResponse::forbidden()).
Declare middleware on an action (or controller class) with the
Middleware attribute — the same
attribute the admin surface uses; only the interface the kernel validates
against differs per surface. The WpRestKernel resolves each entry from
the container and composes them around the action, outermost first (class-level
before method-level). A middleware may inspect or decorate the request,
short-circuit by returning its own WP_REST_Response (the scope/RBAC or
rate-limit gate), or call $next($request) to continue the chain and
post-process the result.
The action's arguments are resolved when the action runs — the innermost link in the chain — so a request rejected by an outer middleware never resolves the action arguments nor touches the controller.
Table of Contents
Methods
- process() : WP_REST_Response
- Process the request, optionally delegating to the rest of the chain.
Methods
process()
Process the request, optionally delegating to the rest of the chain.
public
process(WP_REST_Request $request, callable(WP_REST_Request): WP_REST_Response $next) : WP_REST_Response
Parameters
- $request : WP_REST_Request
- $next : callable(WP_REST_Request): WP_REST_Response
-
the next middleware, or the action