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
← All changes | modules/optimization/rest/cancel-bulk-optimization.php +15 -11 1.0.11.7.7 View file →
@@ -1,15 +1,15 @@
1 1 <?php
2 2
3 -namespace ImageOptimizer\Modules\Optimization\Rest;
3 +namespace ImageOptimization\Modules\Optimization\Rest;
4 4
5 -use ImageOptimizer\Modules\Optimization\Classes\{
6 - Bulk_Optimization,
5 +use ImageOptimization\Modules\Optimization\Classes\{
6 + Bulk_Optimization\Bulk_Optimization_Controller,
7 7 Route_Base,
8 8 };
9 -use ImageOptimizer\Modules\Oauth\Components\Connect;
10 9 use Throwable;
11 10 use WP_REST_Request;
11 +use ImageOptimization\Plugin;
12 12
13 13 if ( ! defined( 'ABSPATH' ) ) {
14 14 exit; // Exit if accessed directly.
15 15 }
@@ -14,9 +14,9 @@
14 14 exit; // Exit if accessed directly.
15 15 }
16 16
17 17 class Cancel_Bulk_Optimization extends Route_Base {
18 - const NONCE_NAME = 'image-optimizer-cancel-bulk-optimization';
18 + const NONCE_NAME = 'image-optimization-cancel-bulk-optimization';
19 19
20 20 protected string $path = 'bulk/cancel';
21 21
22 22 public function get_name(): string {
@@ -27,31 +27,35 @@
27 27 return [ 'POST' ];
28 28 }
29 29
30 30 public function POST( WP_REST_Request $request ) {
31 - $this->verify_nonce_and_capability(
31 + $error = $this->verify_nonce_and_capability(
32 32 $request->get_param( self::NONCE_NAME ),
33 33 self::NONCE_NAME
34 34 );
35 35
36 - if ( ! Connect::is_activated() ) {
36 + if ( $error ) {
37 + return $error;
38 + }
39 +
40 + if ( ! Plugin::instance()->modules_manager->get_modules( 'connect-manager' )->connect_instance->is_activated() ) {
37 41 return $this->respond_error_json([
38 - 'message' => esc_html__( 'Invalid activation', 'image-optimizer' ),
42 + 'message' => esc_html__( 'Invalid activation', 'image-optimization' ),
39 43 'code' => 'unauthorized',
40 44 ]);
41 45 }
42 46
43 47 try {
44 - $is_in_progress = Bulk_Optimization::is_optimization_in_progress();
48 + $is_in_progress = Bulk_Optimization_Controller::is_optimization_in_progress();
45 49
46 50 if ( ! $is_in_progress ) {
47 51 return $this->respond_error_json([
48 - 'message' => esc_html__( 'Bulk optimization is not in progress', 'image-optimizer' ),
52 + 'message' => esc_html__( 'Bulk optimization is not in progress', 'image-optimization' ),
49 53 'code' => 'forbidden',
50 54 ]);
51 55 }
52 56
53 - Bulk_Optimization::cancel_bulk_optimization();
57 + Bulk_Optimization_Controller::delete_bulk_optimization();
54 58
55 59 return $this->respond_success_json();
56 60 } catch ( Throwable $t ) {
57 61 return $this->respond_error_json([