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 / backups / rest / remove-backups.php

remove-backups.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.7, at modules/backups/rest/remove-backups.php

51 lines 991 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Modules\Backups\Rest;
4
5 use ImageOptimization\Modules\Backups\Classes\{
6 Route_Base,
7 Remove_All_Backups,
8 };
9 use Throwable;
10 use WP_REST_Request;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 class Remove_Backups extends Route_Base {
17 const NONCE_NAME = 'image-optimization-remove-backups';
18
19 protected string $path = '';
20
21 public function get_name(): string {
22 return 'remove-backups';
23 }
24
25 public function get_methods(): array {
26 return [ 'DELETE' ];
27 }
28
29 public function DELETE( WP_REST_Request $request ) {
30 $error = $this->verify_nonce_and_capability(
31 $request->get_param( self::NONCE_NAME ),
32 self::NONCE_NAME
33 );
34
35 if ( $error ) {
36 return $error;
37 }
38
39 try {
40 Remove_All_Backups::find_and_schedule_removing();
41
42 return $this->respond_success_json();
43 } catch ( Throwable $t ) {
44 return $this->respond_error_json([
45 'message' => $t->getMessage(),
46 'code' => 'internal_server_error',
47 ]);
48 }
49 }
50 }
51