| 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 |
|