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

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

- Page: https://pluginprobe.com/plugins/metricool/2.0.2/code/app/Http/Middleware/HasMetricoolBlogId.php
- Raw: https://pluginprobe.com/plugins/metricool/2.0.2/raw/app/Http/Middleware/HasMetricoolBlogId.php
- Modified: 2026-06-11T08:45:10+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.0.2/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): ?\WP_REST_Response
    {
        if (!$this->metricool->hasBlogId()) {
            return $this->sendHttpErrorResponse(
                'Brand / blog id missing',
                null,
                403
            );
        }

        return null;
    }
}

```
