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