PluginProbe
Metricool – Social media and site statistics / trunk
Metricool – Social media and site statistics vtrunk
2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Http / Middleware / HasMetricoolBlogId.php

HasMetricoolBlogId.php in Metricool – Social media and site statistics trunk, at app/Http/Middleware/HasMetricoolBlogId.php

38 lines 837 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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