# metricool/2.1.1/app/Http/Middleware/HasMetricoolBlogId.php

Metricool – Social media and site statistics, version 2.1.1. 38 lines.

- Page: https://pluginprobe.com/plugins/metricool/2.1.1/code/app/Http/Middleware/HasMetricoolBlogId.php
- Raw: https://pluginprobe.com/plugins/metricool/2.1.1/raw/app/Http/Middleware/HasMetricoolBlogId.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/2.1.1/code/app/Http/Middleware/HasMetricoolBlogId.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Metricool\Http\Middleware;

use Metricool\Http\Metricool\MetricoolApi;
use Metricool\Interfaces\MiddlewareInterface;
use Metricool\Traits\HasRestAccess;

/**
 * Checks if a brand / blog id is set. This is required for some Metricool API endpoints
 */
class HasMetricoolBlogId implements MiddlewareInterface
{
    use HasRestAccess;

    private MetricoolApi $metricool;

    public function __construct(MetricoolApi $metricool)
    {
        $this->metricool = $metricool;
    }

    public function handle(\WP_REST_Request $request, callable $next)
    {
        if (!$this->metricool->hasBlogId()) {
            return $this->sendHttpErrorResponse(
                'Blog id missing',
                null,
                403
            );
        }

        return $next($request);
    }
}

```
