| @@ -1,14 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace ImageOptimizer\Modules\Stats\Rest; | |
| 3 | +namespace ImageOptimization\Modules\Stats\Rest; | |
| 4 | 4 | |
| 5 | -use ImageOptimizer\Modules\Stats\Classes\{ | |
| 5 | +use ImageOptimization\Modules\Stats\Classes\{ | |
| 6 | 6 | Route_Base, |
| 7 | 7 | Stats |
| 8 | 8 | }; |
| 9 | 9 | use Throwable; |
| 10 | 10 | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit; // Exit if accessed directly. | |
| 13 | +} | |
| 14 | + | |
| 11 | 15 | class Get_Stats extends Route_Base { |
| 12 | 16 | protected string $path = ''; |
| 13 | 17 | |
| 14 | 18 | public function get_name(): string { |
| @@ -19,8 +23,14 @@ | ||
| 19 | 23 | return [ 'GET' ]; |
| 20 | 24 | } |
| 21 | 25 | |
| 22 | 26 | public function GET() { |
| 27 | + $error = $this->verify_capability(); | |
| 28 | + | |
| 29 | + if ( $error ) { | |
| 30 | + return $error; | |
| 31 | + } | |
| 32 | + | |
| 23 | 33 | try { |
| 24 | 34 | return $this->respond_success_json( Stats::calculate_global_stats() ); |
| 25 | 35 | } catch ( Throwable $t ) { |
| 26 | 36 | return $this->respond_error_json([ |