PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.5.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.5.4
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 / connect / rest / switch-domain.php

switch-domain.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.5.4, at modules/connect/rest/switch-domain.php

62 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\Connect\Rest;
4
5 use ImageOptimization\Modules\Connect\Classes\{
6 Data,
7 Route_Base,
8 Service,
9 };
10
11 use Throwable;
12 use WP_REST_Request;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly
16 }
17
18 /**
19 * Class Switch_Domain
20 */
21 class Switch_Domain extends Route_Base {
22 public string $path = 'switch_domain';
23 public const NONCE_NAME = 'wp_rest';
24
25 public function get_methods(): array {
26 return [ 'POST' ];
27 }
28
29 public function get_name(): string {
30 return 'switch_domain';
31 }
32
33 public function POST( WP_REST_Request $request ) {
34 $this->verify_nonce_and_capability(
35 $request->get_param( self::NONCE_NAME ),
36 self::NONCE_NAME
37 );
38
39 try {
40 $client_id = Data::get_client_id();
41
42 if ( ! $client_id ) {
43 return $this->respond_error_json( [
44 'message' => esc_html__( 'Client ID not found', 'image-optimization' ),
45 'code' => 'bad_request',
46 ] );
47 }
48
49 Service::update_redirect_uri();
50
51 return $this->respond_success_json( [
52 'message' => esc_html__( 'Domain updated!', 'image-optimization' ),
53 ] );
54 } catch ( Throwable $t ) {
55 return $this->respond_error_json( [
56 'message' => $t->getMessage(),
57 'code' => 'internal_server_error',
58 ] );
59 }
60 }
61 }
62