PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.6.6
Image Optimization – Compress Images and Convert to WebP or AVIF v1.6.6
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 / oauth / rest / deactivate.php

deactivate.php in Image Optimization – Compress Images and Convert to WebP or AVIF 1.6.6, at modules/oauth/rest/deactivate.php

65 lines 1.4 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\Oauth\Rest;
4
5 use ImageOptimization\Modules\Oauth\{
6 Classes\Data,
7 Classes\Route_Base,
8 Components\Connect
9 };
10 use Throwable;
11 use WP_REST_Request;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 class Deactivate extends Route_Base {
18 const NONCE_NAME = 'image-optimization-deactivate-subscription';
19
20 protected string $path = 'deactivate';
21
22 public function get_name(): string {
23 return 'deactivate';
24 }
25
26 public function get_methods(): array {
27 return [ 'POST' ];
28 }
29
30 public function POST( WP_REST_Request $request ) {
31 $this->verify_nonce_and_capability(
32 $request->get_param( self::NONCE_NAME ),
33 self::NONCE_NAME
34 );
35
36 if ( ! Connect::is_connected() ) {
37 return $this->respond_error_json( [
38 'message' => esc_html__( 'Please connect first', 'image-optimization' ),
39 'code' => 'forbidden',
40 ] );
41 }
42
43 if ( ! $request->get_param( 'license_key' ) ) {
44 return $this->respond_error_json( [
45 'message' => esc_html__( 'Missing license key', 'image-optimization' ),
46 'code' => 'bad_request',
47 ] );
48 }
49
50 $license_key = $request->get_param( 'license_key' );
51
52 try {
53 Connect::deactivate( $license_key );
54
55 return $this->respond_success_json();
56 } catch ( Throwable $t ) {
57 Data::delete_activation_state();
58 return $this->respond_error_json( [
59 'message' => $t->getMessage(),
60 'code' => 'internal_server_error',
61 ] );
62 }
63 }
64 }
65