PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / modules / stats / rest / get-optimization-details.php

get-optimization-details.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.7, at modules/stats/rest/get-optimization-details.php

53 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Modules\Stats\Rest;
4
5 use ImageOptimization\Modules\Stats\Classes\{
6 Optimization_Stats,
7 Route_Base,
8 };
9 use Throwable;
10 use WP_REST_Request;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 class Get_Optimization_Details extends Route_Base {
17 protected string $path = 'optimization-details';
18
19 public function get_name(): string {
20 return 'get-optimization-details';
21 }
22
23 public function get_methods(): array {
24 return [ 'GET' ];
25 }
26
27 public function GET( WP_REST_Request $request ) {
28 $error = $this->verify_capability();
29
30 if ( $error ) {
31 return $error;
32 }
33
34 try {
35 $image_id = $request->get_param( 'image_id' );
36
37 if ( empty( $image_id ) ) {
38 return $this->respond_error_json([
39 'message' => 'Image ID is required',
40 'code' => 'bad_request',
41 ]);
42 }
43
44 return $this->respond_success_json( Optimization_Stats::get_optimization_details( $image_id ) );
45 } catch ( Throwable $t ) {
46 return $this->respond_error_json([
47 'message' => $t->getMessage(),
48 'code' => 'internal_server_error',
49 ]);
50 }
51 }
52 }
53