PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.0.1
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.0.1
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 / oauth / rest / get-subscriptions.php

get-subscriptions.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.0.1, at modules/oauth/rest/get-subscriptions.php

57 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 ImageOptimizer\Modules\Oauth\Rest;
4
5 use ImageOptimizer\Classes\Utils;
6 use ImageOptimizer\Modules\Oauth\Classes\Route_Base;
7 use ImageOptimizer\Modules\Oauth\Components\Connect;
8 use WP_REST_Request;
9
10 class GetSubscriptions extends Route_Base {
11 const NONCE_NAME = 'image-optimizer-get-subscription';
12 protected string $path = 'get-subscriptions';
13
14 public function get_name(): string {
15 return 'get_subscriptions';
16 }
17
18 public function get_methods(): array {
19 return [ 'POST' ];
20 }
21
22 public function POST( WP_REST_Request $request ) {
23 $this->verify_nonce_and_capability(
24 $request->get_param( self::NONCE_NAME ),
25 self::NONCE_NAME
26 );
27
28 if ( ! Connect::is_connected() ) {
29 return $this->respond_error_json( [
30 'message' => esc_html__( 'Please connect first', 'image-optimizer' ),
31 'code' => 'forbidden',
32 ] );
33 }
34
35 $response = Utils::get_api_client()->make_request(
36 'POST',
37 'activation/get-subscriptions'
38 );
39
40 if ( is_wp_error( $response ) ) {
41 return $this->respond_error_json( [
42 'message' => $response->get_error_message(),
43 'code' => 'internal_server_error',
44 ] );
45 }
46
47 if ( ! isset( $response->subscriptions ) ) {
48 return $this->respond_error_json( [
49 'message' => esc_html__( 'Invalid response from server', 'image-optimizer' ),
50 'code' => 'internal_server_error',
51 ] );
52 }
53
54 return $this->respond_success_json( $response->subscriptions );
55 }
56 }
57