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 / IsWordPressAdminRequest.php

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

30 lines 714 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\Interfaces\MiddlewareInterface;
8 use Metricool\Traits\HasRestAccess;
9
10 /**
11 * Checks if the current request is made from the WordPress admin. If not, it returns a 401 Unauthorized response.
12 */
13 class IsWordPressAdminRequest implements MiddlewareInterface
14 {
15 use HasRestAccess;
16
17 public function handle(\WP_REST_Request $request, callable $next)
18 {
19 if (!is_admin()) {
20 return $this->sendHttpErrorResponse(
21 __('Unauthorized. Please log in into the WordPress admin.', 'metricool'),
22 null,
23 401
24 );
25 }
26
27 return $next($request);
28 }
29 }
30