PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / trunk
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More vtrunk
4.2.0 4.1.0 4.0.9 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
wizard 3 weeks ago class-dashboard-controller.php 4 hours ago class-license-resolve-controller.php 3 weeks ago class-newsletter-signup-controller.php 3 weeks ago class-notice-controller.php 3 weeks ago class-plugin-reset-controller.php 3 weeks ago class-review-controller.php 3 weeks ago class-rewrite-check-controller.php 3 weeks ago class-settings-controller.php 3 weeks ago class-troubleshooting-controller.php 2 weeks ago
class-troubleshooting-controller.php
296 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\Tours\Controllers\TourController;
15 use SuperbAddons\Data\Controllers\LogController;
16 use Exception;
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 TourController::CleanUpTourPage($request['tour-nonce']);
73 return rest_ensure_response(['success' => true]);
74 case 'mark-tour-complete':
75 $tour = isset($request['tour']) ? sanitize_text_field($request['tour']) : '';
76 $allowed = array(TourController::TOUR_DASHBOARD_WELCOME_META, TourController::TOUR_BLOCK_THEME_META);
77 if (!in_array($tour, $allowed, true)) {
78 return new \WP_Error('bad_request_plugin', 'Invalid tour', array('status' => 400));
79 }
80 TourController::MarkTourCompleted($tour);
81 return rest_ensure_response(array('success' => true));
82 default:
83 return new \WP_Error('bad_request_plugin', 'Bad Plugin Request', array('status' => 400));
84 }
85 } catch (Exception $ex) {
86 LogController::HandleException($ex);
87 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
88 }
89 }
90
91 public function TroubleshootingRouteCallback($request)
92 {
93 if (!isset($request['action'])) {
94 return new \WP_Error('bad_request_plugin', 'Bad Plugin Request', array('status' => 400));
95 }
96 switch ($request['action']) {
97 case 'restcheck':
98 return $this->RestCheckCallback();
99 case 'restfix':
100 return $this->RestFixCallback();
101 case 'connection':
102 return $this->ConnectionCheckCallback();
103 case 'domainshift':
104 return $this->DomainShiftCallback();
105 case 'service':
106 return $this->ServiceCheckCallback();
107 case 'keycheck':
108 return $this->KeyCheckCallback();
109 case 'keyverify':
110 return $this->KeyVerifyCallback();
111 case 'cacheclear':
112 return $this->CacheClearCallback();
113 default:
114 return new \WP_Error('bad_request_plugin', 'Bad Plugin Request', array('status' => 400));
115 }
116 }
117
118 private function RestCheckCallback()
119 {
120 try {
121 // If we reached this endpoint, the REST API is at least partially working.
122 // Check if rewrite rules are properly configured.
123 $permalink_structure = get_option('permalink_structure');
124 if (empty($permalink_structure)) {
125 // Plain permalinks — REST API uses ?rest_route= which always works.
126 return rest_ensure_response(array('success' => true));
127 }
128
129 $rules = get_option('rewrite_rules');
130 if (empty($rules) || !is_array($rules)) {
131 return rest_ensure_response(array(
132 'success' => false,
133 'requiresConsent' => true,
134 'text' => esc_html__('WordPress rewrite rules are not configured', 'superb-blocks'),
135 ));
136 }
137
138 $rest_prefix = rest_get_url_prefix();
139 foreach ($rules as $pattern => $query) {
140 if (strpos($pattern, $rest_prefix) !== false) {
141 return rest_ensure_response(array('success' => true));
142 }
143 }
144
145 return rest_ensure_response(array(
146 'success' => false,
147 'requiresConsent' => true,
148 'text' => esc_html__('REST API rewrite rules are missing', 'superb-blocks'),
149 ));
150 } catch (Exception $ex) {
151 LogController::HandleException($ex);
152 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
153 }
154 }
155
156 private function RestFixCallback()
157 {
158 try {
159 flush_rewrite_rules();
160
161 // Verify the fix worked
162 $rules = get_option('rewrite_rules');
163 if (!empty($rules) && is_array($rules)) {
164 $rest_prefix = rest_get_url_prefix();
165 foreach ($rules as $pattern => $query) {
166 if (strpos($pattern, $rest_prefix) !== false) {
167 RewriteCheckController::ClearIssue();
168 return rest_ensure_response(array('success' => true));
169 }
170 }
171 }
172
173 return rest_ensure_response(array('success' => false));
174 } catch (Exception $ex) {
175 LogController::HandleException($ex);
176 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
177 }
178 }
179
180 private function ConnectionCheckCallback()
181 {
182 try {
183 $is_connected = DomainShiftController::GetCurrentConnectionSuccess();
184
185 return rest_ensure_response(['success' => $is_connected]);
186 } catch (Exception $ex) {
187 LogController::HandleException($ex);
188 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
189 }
190 }
191
192 private function DomainShiftCallback()
193 {
194 try {
195 $successful_shift = DomainShiftController::FindPreferredAPIDomain();
196
197 return rest_ensure_response(['success' => $successful_shift]);
198 } catch (Exception $ex) {
199 LogController::HandleException($ex);
200 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
201 }
202 }
203
204 private function ServiceCheckCallback()
205 {
206 try {
207 $status_arr = DomainShiftController::GetServiceStatus();
208 if ($status_arr['online']) {
209 return rest_ensure_response(['success' => true]);
210 }
211
212 return rest_ensure_response(['success' => false, "text" => esc_html($status_arr['message'])]);
213 } catch (Exception $ex) {
214 LogController::HandleException($ex);
215 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
216 }
217 }
218
219 private function KeyCheckCallback()
220 {
221 try {
222 $keytype_label = KeyController::GetCurrentKeyTypeLabel();
223 if (!KeyController::HasRegisteredKey()) {
224 // No need to check for key status if no key is registered.
225 return rest_ensure_response(['success' => true, "text" => esc_html($keytype_label)]);
226 }
227
228 $keyinfo = KeyController::GetKeyStatus();
229
230 if ($keyinfo['expired']) {
231 return rest_ensure_response(['success' => false, "ignoreResolver" => false, "text" => esc_html__('Subscription Expired', "superb-blocks")]);
232 }
233
234 if (!$keyinfo['active']) {
235 return rest_ensure_response(['success' => false, "ignoreResolver" => false, "text" => esc_html__('License Key Disabled. Please contact our support team for assistance.', "superb-blocks")]);
236 }
237
238 if (!$keyinfo['verified']) {
239 return rest_ensure_response(['success' => false, "text" => esc_html__('License Key Verification Invalid', "superb-blocks")]);
240 }
241
242 if ($keyinfo['exceeded']) {
243 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")]);
244 }
245
246 return rest_ensure_response(['success' => true, "text" => esc_html($keytype_label)]);
247 } catch (KeyException $k_ex) {
248 return rest_ensure_response(['success' => false, "text" => esc_html($k_ex->getMessage())]);
249 } catch (Exception $ex) {
250 LogController::HandleException($ex);
251 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
252 }
253 }
254
255
256 private function KeyVerifyCallback()
257 {
258 try {
259 $keyinfo = KeyController::GetUpdatedLicenseKeyInformation();
260 if (($keyinfo['expired'] && $keyinfo['type'] !== KeyType::STANDARD) || !$keyinfo['active'] || !$keyinfo['verified'] || $keyinfo['exceeded']) {
261 if ($keyinfo['expired'] && $keyinfo['type'] !== KeyType::STANDARD) {
262 return rest_ensure_response(['success' => false, "text" => esc_html__('License Subscription Expired', "superb-blocks")]);
263 }
264
265 if ($keyinfo['exceeded']) {
266 if ($keyinfo['expired']) {
267 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")]);
268 }
269 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")]);
270 }
271
272 return rest_ensure_response(['success' => false]);
273 }
274 $keytype_label = KeyController::GetKeyTypeLabel($keyinfo['type']);
275 return rest_ensure_response(['success' => true, "text" => esc_html($keytype_label . ' ' . __('Verified', "superb-blocks"))]);
276 } catch (KeyException $k_ex) {
277 return rest_ensure_response(['success' => false, "text" => esc_html($k_ex->getMessage())]);
278 } catch (Exception $ex) {
279 LogController::HandleException($ex);
280 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
281 }
282 }
283
284 private function CacheClearCallback()
285 {
286 try {
287 $cleared = CacheController::ClearCache(CacheOptions::SERVICE_VERSION) && CacheController::ClearCache(ElementorCache::SECTIONS);
288
289 return rest_ensure_response(['success' => $cleared]);
290 } catch (Exception $ex) {
291 LogController::HandleException($ex);
292 return new \WP_Error('internal_error_plugin', 'Internal Plugin Error', array('status' => 500));
293 }
294 }
295 }
296