PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.1.0
Image Optimization – Compress Images and Convert to WebP or AVIF v1.1.0
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 1.6.6 All 32 releases
image-optimization / modules / optimization / rest / optimization-status.php

optimization-status.php in Image Optimization – Compress Images and Convert to WebP or AVIF 1.1.0, at modules/optimization/rest/optimization-status.php

48 lines 1.2 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\Optimization\Rest;
4
5 use ImageOptimization\Modules\Optimization\Classes\Optimization_Status as Optimization_Status_Controller;
6 use ImageOptimization\Modules\Optimization\Classes\Route_Base;
7 use Throwable;
8 use WP_REST_Request;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 class Optimization_Status extends Route_Base {
15 protected string $path = 'status';
16
17 public function get_name(): string {
18 return 'optimization-status';
19 }
20
21 public function get_methods(): array {
22 // There might be a huge amount of ids in some cases, so decided to keep it as POST
23 return [ 'POST' ];
24 }
25
26 public function POST( WP_REST_Request $request ) {
27 try {
28 $body = json_decode( $request->get_body() );
29 $image_ids = $body->image_ids ?? null;
30
31 if ( empty( $image_ids ) ) {
32 return $this->respond_success_json([
33 'status' => [],
34 ]);
35 }
36
37 return $this->respond_success_json([
38 'status' => Optimization_Status_Controller::get_images_optimization_statuses( $image_ids ),
39 ]);
40 } catch ( Throwable $t ) {
41 return $this->respond_error_json([
42 'message' => $t->getMessage(),
43 'code' => 'internal_server_error',
44 ]);
45 }
46 }
47 }
48