# metricool/trunk/app/Interfaces/MiddlewareInterface.php

Metricool – Social media and site statistics, version trunk. 31 lines.

- Page: https://pluginprobe.com/plugins/metricool/trunk/code/app/Interfaces/MiddlewareInterface.php
- Raw: https://pluginprobe.com/plugins/metricool/trunk/raw/app/Interfaces/MiddlewareInterface.php
- Modified: 2026-08-20T14:08:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/metricool/trunk/code/app/Interfaces/MiddlewareInterface.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Metricool\Interfaces;

interface MiddlewareInterface
{
    /**
     * Handle an incoming REST request as part of the middleware pipeline.
     *
     * Middleware are composed into an "onion" pipeline by
     * {@see \Metricool\Managers\EndpointManager::callbackMiddleware()}, where each
     * layer wraps the next one and the endpoint callback sits at the core.
     *
     * Continue the request with: `return $next($request);`
     *
     * Short-circuit: return a `\WP_REST_Response` directly,
     *    e.g. a 403 when an authorization check fails. Neither the remaining
     *    middleware nor the endpoint callback will run.
     *
     * Thrown exceptions are caught by the pipeline wrapper and converted into a
     * 500 `\WP_REST_Response` containing the exception message.
     *
     * @param \WP_REST_Request $request The incoming REST request.
     * @param callable(\WP_REST_Request): mixed $next The next middleware in the pipeline
     * @return mixed `$next($request)` or `\WP_REST_Response` when short-circuiting.
     */
    public function handle(\WP_REST_Request $request, callable $next);
}

```
