| @@ -1,11 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\App\Modules\SiteBuilder\Rest; |
| 3 | 3 | |
| 4 | -use Elementor\App\Modules\SiteBuilder\Services\Connect_Auth_Service; | |
| 5 | 4 | use Elementor\Plugin; |
| 6 | 5 | use WP_Error; |
| 7 | -use WP_Http; | |
| 8 | 6 | use WP_REST_Response; |
| 9 | 7 | use WP_REST_Server; |
| 10 | 8 | |
| 11 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -23,14 +21,8 @@ | ||
| 23 | 21 | 'callback' => [ $this, 'get_home_screen' ], |
| 24 | 22 | 'permission_callback' => fn() => current_user_can( 'manage_options' ), |
| 25 | 23 | ] ); |
| 26 | 24 | |
| 27 | - register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/auth', [ | |
| 28 | - 'methods' => WP_REST_Server::READABLE, | |
| 29 | - 'callback' => [ $this, 'get_auth_credentials' ], | |
| 30 | - 'permission_callback' => fn() => current_user_can( 'manage_options' ), | |
| 31 | - ] ); | |
| 32 | - | |
| 33 | 25 | register_rest_route( self::API_NAMESPACE, '/' . self::API_BASE . '/snapshot', [ |
| 34 | 26 | [ |
| 35 | 27 | 'methods' => WP_REST_Server::READABLE, |
| 36 | 28 | 'callback' => [ $this, 'get_snapshot' ], |
| @@ -55,9 +47,9 @@ | ||
| 55 | 47 | public function get_home_screen() { |
| 56 | 48 | $app = $this->get_connect_app(); |
| 57 | 49 | |
| 58 | 50 | if ( ! $app || ! $app->is_connected() ) { |
| 59 | - return new WP_Error( 'site_builder_unavailable', 'Site builder is not connected.', [ 'status' => WP_Http::SERVICE_UNAVAILABLE ] ); | |
| 51 | + return new WP_Error( 'site_builder_unavailable', 'Site builder is not connected.', [ 'status' => 503 ] ); | |
| 60 | 52 | } |
| 61 | 53 | |
| 62 | 54 | $data = $app->get_home_screen(); |
| 63 | 55 | |
| @@ -64,38 +56,17 @@ | ||
| 64 | 56 | if ( is_wp_error( $data ) ) { |
| 65 | 57 | return $data; |
| 66 | 58 | } |
| 67 | 59 | |
| 68 | - return new WP_REST_Response( $data, WP_Http::OK ); | |
| 60 | + return new WP_REST_Response( $data, 200 ); | |
| 69 | 61 | } |
| 70 | 62 | |
| 71 | - public function get_auth_credentials() { | |
| 72 | - $connect_auth = ( new Connect_Auth_Service() )->get_connect_auth(); | |
| 73 | - | |
| 74 | - if ( ! $connect_auth ) { | |
| 75 | - return new WP_Error( | |
| 76 | - 'auth_unavailable', | |
| 77 | - 'Authentication credentials not available', | |
| 78 | - [ 'status' => WP_Http::SERVICE_UNAVAILABLE ] | |
| 79 | - ); | |
| 80 | - } | |
| 81 | - | |
| 82 | - $response = new WP_REST_Response( [ | |
| 83 | - 'success' => true, | |
| 84 | - 'data' => $connect_auth, | |
| 85 | - ], WP_Http::OK ); | |
| 86 | - | |
| 87 | - $response->header( 'Cache-Control', 'no-store, private' ); | |
| 88 | - | |
| 89 | - return $response; | |
| 90 | - } | |
| 91 | - | |
| 92 | 63 | public function get_snapshot() { |
| 93 | 64 | $snapshot = get_option( 'elementor_site_builder_snapshot', [] ); |
| 94 | 65 | return new WP_REST_Response( [ |
| 95 | 66 | 'success' => true, |
| 96 | 67 | 'data' => [ 'value' => $snapshot ], |
| 97 | - ], WP_Http::OK ); | |
| 68 | + ], 200 ); | |
| 98 | 69 | } |
| 99 | 70 | |
| 100 | 71 | public function update_snapshot( $request ) { |
| 101 | 72 | $value = $request->get_param( 'value' ); |
| @@ -104,9 +75,9 @@ | ||
| 104 | 75 | if ( count( $sanitized ) > self::SNAPSHOT_MAX_KEYS ) { |
| 105 | 76 | return new WP_REST_Response( [ |
| 106 | 77 | 'success' => false, |
| 107 | 78 | 'data' => [ 'message' => 'Snapshot exceeds maximum allowed size.' ], |
| 108 | - ], WP_Http::BAD_REQUEST ); | |
| 79 | + ], 400 ); | |
| 109 | 80 | } |
| 110 | 81 | |
| 111 | 82 | $success = update_option( 'elementor_site_builder_snapshot', $sanitized, false ); |
| 112 | 83 | |
| @@ -113,15 +84,15 @@ | ||
| 113 | 84 | if ( $success || get_option( 'elementor_site_builder_snapshot' ) === $sanitized ) { |
| 114 | 85 | return new WP_REST_Response( [ |
| 115 | 86 | 'success' => true, |
| 116 | 87 | 'data' => [ 'message' => 'Snapshot updated successfully.' ], |
| 117 | - ], WP_Http::OK ); | |
| 88 | + ], 200 ); | |
| 118 | 89 | } |
| 119 | 90 | |
| 120 | 91 | return new WP_REST_Response( [ |
| 121 | 92 | 'success' => false, |
| 122 | 93 | 'data' => [ 'message' => 'Failed to update snapshot.' ], |
| 123 | - ], WP_Http::INTERNAL_SERVER_ERROR ); | |
| 94 | + ], 500 ); | |
| 124 | 95 | } |
| 125 | 96 | |
| 126 | 97 | protected function get_connect_app() { |
| 127 | 98 | if ( ! Plugin::$instance->common ) { |