| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Metricool\Http\Middleware; |
| 6 |
|
| 7 |
use Metricool\Http\Metricool\MetricoolApi; |
| 8 |
use Metricool\Interfaces\MiddlewareInterface; |
| 9 |
use Metricool\Traits\HasRestAccess; |
| 10 |
|
| 11 |
/** |
| 12 |
* Checks if a brand / blog id is set. This is required for some Metricool API endpoints |
| 13 |
*/ |
| 14 |
class HasMetricoolBlogId implements MiddlewareInterface |
| 15 |
{ |
| 16 |
use HasRestAccess; |
| 17 |
|
| 18 |
private MetricoolApi $metricool; |
| 19 |
|
| 20 |
public function __construct(MetricoolApi $metricool) |
| 21 |
{ |
| 22 |
$this->metricool = $metricool; |
| 23 |
} |
| 24 |
|
| 25 |
public function handle(\WP_REST_Request $request, callable $next) |
| 26 |
{ |
| 27 |
if (!$this->metricool->hasBlogId()) { |
| 28 |
return $this->sendHttpErrorResponse( |
| 29 |
'Blog id missing', |
| 30 |
null, |
| 31 |
403 |
| 32 |
); |
| 33 |
} |
| 34 |
|
| 35 |
return $next($request); |
| 36 |
} |
| 37 |
} |
| 38 |
|