PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / 3.1.0
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More v3.1.0
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 trunk 1.0.0 2.0.0 2.0.1 2.0.2 2.0.3 3.0 3.0.1 3.0.2 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1
superb-blocks / src / admin / controllers / class-troubleshooting-controller.php
superb-blocks / src / admin / controllers Last commit date
class-dashboard-controller.php 2 years ago class-notice-controller.php 2 years ago class-settings-controller.php 2 years ago class-troubleshooting-controller.php 2 years ago
class-troubleshooting-controller.php
239 lines
1 <?php
2
3 namespace SuperbAddons\Admin\Controllers;
4
5 use SuperbAddons\Config\Capabilities;
6 use SuperbAddons\Data\Controllers\CacheController;
7 use SuperbAddons\Data\Controllers\DomainShiftController;
8 use SuperbAddons\Data\Controllers\KeyController;
9 use SuperbAddons\Data\Controllers\RestController;
10 use SuperbAddons\Data\Utils\CacheOptions;
11 use SuperbAddons\Data\Utils\ElementorCache;
12 use SuperbAddons\Data\Utils\KeyException;
13 use SuperbAddons\Elementor\Controllers\ElementorController;
14 use SuperbAddons\Gutenberg\Controllers\GutenbergController;
15 use SuperbAddons\Tours\Controllers\TourController;
16
17 defined('ABSPATH') || exit();
18
19 class TroubleshootingController
20 {
21 const TROUBLESHOOTING_ROUTE = '/troubleshooting';
22 const TUTORIAL_ROUTE = '/tutorial';
23
24 const ENDPOINT_BASE = 'addons-status/';
25
26 public function __construct()
27 {
28 RestController::AddRoute(self::TROUBLESHOOTING_ROUTE, array(
29 'methods' => 'POST',
30 'permission_callback' => array($this, 'TroubleshootingCallbackPermissionCheck'),
31 'callback' => array($this, 'TroubleshootingRouteCallback'),
32 ));
33 RestController::AddRoute(self::TUTORIAL_ROUTE, array(
34 'methods' => 'POST',
35 'permission_callback' => array($this, 'TutorialCallbackPermissionCheck'),
36 'callback' => array($this, 'TutorialRouteCallback'),
37 ));
38 }
39
40 public function TroubleshootingCallbackPermissionCheck()
41 {
42 // Restrict endpoint to only users who have the proper capability.
43 if (!current_user_can(Capabilities::ADMIN)) {
44 return new WP_Error('rest_forbidden', esc_html__('Unauthorized. Please check user permissions.', "superb-blocks"), array('status' => 401));
45 }
46
47 return true;
48 }
49
50 public function TutorialCallbackPermissionCheck()
51 {
52 // Restrict endpoint to only users who have the proper capability.
53 if (!current_user_can(Capabilities::CONTRIBUTOR)) {
54 return new WP_Error('rest_forbidden', esc_html__('Unauthorized. Please check user permissions.', "superb-blocks"), array('status' => 401));
55 }
56
57 return true;
58 }
59
60 public function TutorialRouteCallback($request)
61 {
62 if (!isset($request['action'])) {
63 return new \WP_Error('bad_request_plugin', 'Bad Plugin Request', array('status' => 400));
64 }
65 try {
66 switch ($request['action']) {
67 case 'elementor-tour':
68 $url = TourController::GetElementorTourURL();
69 return rest_ensure_response(['success' => true, 'url' => esc_url_raw($url)]);
70 case 'cleanup-elementor-tour-page':
71 $removed = TourController::CleanUpTourPage($request['tour-nonce']);
72 return rest_ensure_response(['success' => $removed]);
73 default:
74 return new \WP_Error('bad_request_plugin', 'Bad Plugin Request', array('status' => 400));
75 }
76 } catch (Exception $ex) {
77 LogController::HandleException($ex);
78 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
79 }
80 }
81
82 public function TroubleshootingRouteCallback($request)
83 {
84 if (!isset($request['action'])) {
85 return new \WP_Error('bad_request_plugin', 'Bad Plugin Request', array('status' => 400));
86 }
87 switch ($request['action']) {
88 case 'wordpressversion':
89 return $this->WordPressVersionCallback();
90 case 'elementorversion':
91 return $this->ElementorVersionCallback();
92 case 'connection':
93 return $this->ConnectionCheckCallback();
94 case 'domainshift':
95 return $this->DomainShiftCallback();
96 case 'service':
97 return $this->ServiceCheckCallback();
98 case 'keycheck':
99 return $this->KeyCheckCallback();
100 case 'keyverify':
101 return $this->KeyVerifyCallback();
102 case 'cacheclear':
103 return $this->CacheClearCallback();
104 default:
105 return new \WP_Error('bad_request_plugin', 'Bad Plugin Request', array('status' => 400));
106 }
107 }
108
109 private function WordPressVersionCallback()
110 {
111 try {
112 $is_compatible = GutenbergController::is_compatible();
113
114 return rest_ensure_response(['success' => $is_compatible]);
115 } catch (Exception $ex) {
116 LogController::HandleException($ex);
117 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
118 }
119 }
120
121 private function ElementorVersionCallback()
122 {
123 try {
124 $is_compatible = ElementorController::is_compatible();
125
126 return rest_ensure_response(['success' => $is_compatible]);
127 } catch (Exception $ex) {
128 LogController::HandleException($ex);
129 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
130 }
131 }
132
133 private function ConnectionCheckCallback()
134 {
135 try {
136 $is_connected = DomainShiftController::GetCurrentConnectionSuccess();
137
138 return rest_ensure_response(['success' => $is_connected]);
139 } catch (Exception $ex) {
140 LogController::HandleException($ex);
141 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
142 }
143 }
144
145 private function DomainShiftCallback()
146 {
147 try {
148 $successful_shift = DomainShiftController::FindPreferredAPIDomain();
149
150 return rest_ensure_response(['success' => $successful_shift]);
151 } catch (Exception $ex) {
152 LogController::HandleException($ex);
153 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
154 }
155 }
156
157 private function ServiceCheckCallback()
158 {
159 try {
160 $status_arr = DomainShiftController::GetServiceStatus();
161 if ($status_arr['online']) {
162 return rest_ensure_response(['success' => true]);
163 }
164
165 return rest_ensure_response(['success' => false, "text" => esc_html($status_arr['message'])]);
166 } catch (Exception $ex) {
167 LogController::HandleException($ex);
168 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
169 }
170 }
171
172 private function KeyCheckCallback()
173 {
174 try {
175 $keytype_label = KeyController::GetCurrentKeyTypeLabel();
176 if (!KeyController::HasRegisteredKey()) {
177 // No need to check for key status if no key is registered.
178 return rest_ensure_response(['success' => true, "text" => esc_html($keytype_label)]);
179 }
180
181 $keyinfo = KeyController::GetKeyStatus();
182
183 if ($keyinfo['expired']) {
184 return rest_ensure_response(['success' => false, "ignoreResolver" => false, "text" => esc_html__('License Key Expired', "superb-blocks")]);
185 }
186
187 if (!$keyinfo['active']) {
188 return rest_ensure_response(['success' => false, "ignoreResolver" => false, "text" => esc_html__('License Key Disabled. Please contact our support team for assistance.', "superb-blocks")]);
189 }
190
191 if (!$keyinfo['verified']) {
192 return rest_ensure_response(['success' => false, "text" => esc_html__('License Key Verification Invalid', "superb-blocks")]);
193 }
194
195 if ($keyinfo['exceeded']) {
196 return rest_ensure_response(['success' => false, "ignoreResolver" => false, "text" => esc_html__('License Key active on too many domains. Please contact our support team for assistance.', "superb-blocks")]);
197 }
198
199 return rest_ensure_response(['success' => true, "text" => esc_html($keytype_label)]);
200 } catch (KeyException $k_ex) {
201 return rest_ensure_response(['success' => false, "text" => esc_html($k_ex->getMessage())]);
202 } catch (Exception $ex) {
203 LogController::HandleException($ex);
204 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
205 }
206 }
207
208
209 private function KeyVerifyCallback()
210 {
211 try {
212 $keyinfo = KeyController::GetUpdatedLicenseKeyInformation();
213
214 if ($keyinfo['expired'] || !$keyinfo['active'] || !$keyinfo['verified'] || $keyinfo['exceeded']) {
215 return rest_ensure_response(['success' => false]);
216 }
217 $keytype_label = KeyController::GetKeyTypeLabel($keyinfo['type']);
218 return rest_ensure_response(['success' => true, "text" => esc_html($keytype_label . ' ' . __('Verified', "superb-blocks"))]);
219 } catch (KeyException $k_ex) {
220 return rest_ensure_response(['success' => false, "text" => esc_html($k_ex->getMessage())]);
221 } catch (Exception $ex) {
222 LogController::HandleException($ex);
223 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
224 }
225 }
226
227 private function CacheClearCallback()
228 {
229 try {
230 $cleared = CacheController::ClearCache(CacheOptions::SERVICE_VERSION) && CacheController::ClearCache(ElementorCache::SECTIONS);
231
232 return rest_ensure_response(['success' => $cleared]);
233 } catch (Exception $ex) {
234 LogController::HandleException($ex);
235 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
236 }
237 }
238 }
239