PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / 3.2.4
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More v3.2.4
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-dashboard-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-dashboard-controller.php
435 lines
1 <?php
2
3 namespace SuperbAddons\Admin\Controllers;
4
5 defined('ABSPATH') || exit();
6
7 use SuperbAddons\Admin\Pages\AdditionalCSSPage;
8 use SuperbAddons\Admin\Pages\DashboardPage;
9 use SuperbAddons\Admin\Pages\ElementorDashboardPage;
10 use SuperbAddons\Admin\Pages\GutenbergDashboardPage;
11 use SuperbAddons\Admin\Pages\SettingsPage;
12 use SuperbAddons\Admin\Pages\SupportPage;
13 use SuperbAddons\Components\Admin\FeedbackModal;
14 use SuperbAddons\Config\Capabilities;
15 use SuperbAddons\Data\Controllers\RestController;
16
17 use SuperbAddons\Components\Admin\Navigation;
18 use SuperbAddons\Data\Controllers\CSSController;
19 use SuperbAddons\Data\Controllers\KeyController;
20 use SuperbAddons\Elementor\Controllers\ElementorController;
21 use SuperbAddons\Gutenberg\Controllers\GutenbergController;
22
23 class DashboardController
24 {
25 const MENU_SLUG = 'superbaddons';
26 const DASHBOARD = 'dashboard';
27 const ELEMENTOR_DASHBOARD = 'superbaddons-element-dashboard';
28 const GUTENBERG_DASHBOARD = 'superbaddons-gutenberg-dashboard';
29 const ADDITIONAL_CSS = 'superbaddons-additional-css';
30 const SETTINGS = 'superbaddons-settings';
31 const SUPPORT = 'superbaddons-support';
32
33 const PREMIUM_CLASS = 'superbaddons-get-premium';
34
35 private $hooks;
36
37 public function __construct()
38 {
39 new SettingsController();
40 new TroubleshootingController();
41 $this->hooks = array();
42 add_action("admin_menu", array($this, 'SuperbAddonsAdminMenu'));
43 add_filter('plugin_action_links_' . SUPERBADDONS_BASE, array($this, 'PluginActions'));
44 add_action('admin_enqueue_scripts', array($this, 'AdminMenuEnqueues'), 1000);
45 if (!KeyController::HasValidPremiumKey()) {
46 add_action("admin_head", array($this, 'AdminMenuHighlightScripts'));
47 }
48 $this->HandleNotices();
49 }
50
51
52 public function PluginActions($actions)
53 {
54 $added_actions = array(
55 "<a href='" . esc_url(admin_url("admin.php?page=" . self::MENU_SLUG)) . "'>" . esc_html__('Dashboard', "superb-blocks") . "</a>",
56 "<a href='" . esc_url(admin_url("admin.php?page=" . self::SETTINGS)) . "'>" . esc_html__('Settings', "superb-blocks") . "</a>",
57 "<a href='" . esc_url(admin_url("admin.php?page=" . self::SUPPORT)) . "'>" . esc_html__('Support', "superb-blocks") . "</a>"
58 );
59 $actions = array_merge($added_actions, $actions);
60 if (!KeyController::HasValidPremiumKey()) {
61 $actions[] = "<a href='" . esc_url("https://superbthemes.com/superb-addons/") . "' class='" . self::PREMIUM_CLASS . "' target='_blank'>" . esc_html__('Get Premium', "superb-blocks") . "</a>";
62 }
63 return $actions;
64 }
65
66 public function SuperbAddonsAdminMenu()
67 {
68 add_menu_page(esc_html__('Superb Addons', "superb-blocks"), esc_html__('Superb Addons', "superb-blocks") . $this->GetAdminMenuNotification(), Capabilities::CONTRIBUTOR, self::MENU_SLUG, array($this, 'SuperbDashboard'), SUPERBADDONS_ASSETS_PATH . '/img/icon-superb-dashboard-menu.png', '58.6');
69 $this->hooks[self::DASHBOARD] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Dashboard', "superb-blocks"), esc_html__('Dashboard', "superb-blocks"), Capabilities::CONTRIBUTOR, self::MENU_SLUG);
70 $this->hooks[self::GUTENBERG_DASHBOARD] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Gutenberg', "superb-blocks"), esc_html__('Gutenberg Addons', "superb-blocks"), Capabilities::CONTRIBUTOR, self::GUTENBERG_DASHBOARD, array($this, 'GutenbergDashboard'));
71 $this->hooks[self::ELEMENTOR_DASHBOARD] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Elementor', "superb-blocks"), esc_html__('Elementor Addons', "superb-blocks"), Capabilities::CONTRIBUTOR, self::ELEMENTOR_DASHBOARD, array($this, 'ElementorDashboard'));
72 $this->hooks[self::ADDITIONAL_CSS] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Custom CSS', "superb-blocks"), esc_html__('Custom CSS', "superb-blocks"), Capabilities::ADMIN, self::ADDITIONAL_CSS, array($this, 'AdditionalCSS'));
73 $this->hooks[self::SETTINGS] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Settings', "superb-blocks"), esc_html__('Settings', "superb-blocks") . $this->GetAdminMenuNotification(), Capabilities::ADMIN, self::SETTINGS, array($this, 'Settings'));
74 $this->hooks[self::SUPPORT] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Get Help', "superb-blocks"), esc_html__('Get Help', "superb-blocks"), Capabilities::CONTRIBUTOR, self::SUPPORT, array($this, 'Support'));
75 }
76
77 private function GetAdminMenuNotification()
78 {
79 $HasRegisteredKey = KeyController::HasRegisteredKey();
80 if ($HasRegisteredKey) {
81 $KeyStatus = KeyController::GetKeyStatus();
82 if (!$KeyStatus['active'] || $KeyStatus['expired'] || !$KeyStatus['verified'] || $KeyStatus['exceeded']) {
83 return sprintf('<span class="update-plugins count-1"><span class="plugin-count" aria-hidden="true">1</span><span class="screen-reader-text">%s</span></span>', esc_html__("Issue Detected", "superb-blocks"));
84 }
85 }
86
87 return;
88 }
89
90 public function AdminMenuHighlightScripts()
91 {
92 ?>
93 <style>
94 tbody#the-list .<?= self::PREMIUM_CLASS ?> {
95 color: #4312E2;
96 font-weight: 900;
97 }
98 </style>
99 <?php
100 }
101
102 public function HandleNotices()
103 {
104 $options = array("notices" => array());
105 if (!KeyController::HasValidPremiumKey()) {
106 $options["notices"][] = array(
107 'unique_id' => 'addons_delayed',
108 'content' => "addons-notice.php",
109 'delay' => '+6 days'
110 );
111 }
112 AdminNoticeController::init($options);
113 }
114
115 public function AdminMenuEnqueues($page_hook)
116 {
117 if ($page_hook === 'plugins.php') {
118 wp_enqueue_style(
119 'superb-addons-elements',
120 SUPERBADDONS_ASSETS_PATH . '/css/framework.min.css',
121 array(),
122 SUPERBADDONS_VERSION
123 );
124 wp_enqueue_style(
125 'superb-addons-font-manrope',
126 SUPERBADDONS_ASSETS_PATH . '/fonts/manrope/manrope.css',
127 array(),
128 SUPERBADDONS_VERSION
129 );
130 wp_enqueue_style(
131 'superb-addons-admin-modal',
132 SUPERBADDONS_ASSETS_PATH . '/css/admin-modal.min.css',
133 array(),
134 SUPERBADDONS_VERSION
135 );
136
137 wp_enqueue_script('superb-addons-feedback', SUPERBADDONS_ASSETS_PATH . '/js/admin/deactivate-feedback.js', array('jquery'), SUPERBADDONS_VERSION, true);
138 wp_localize_script('superb-addons-feedback', 'superbaddonssettings_g', array(
139 "plugin" => plugin_basename(SUPERBADDONS_BASE),
140 "rest" => array(
141 "base" => \get_rest_url(),
142 "namespace" => RestController::NAMESPACE,
143 "nonce" => wp_create_nonce("wp_rest"),
144 "routes" => array(
145 "settings" => SettingsController::SETTINGS_ROUTE,
146 )
147 )
148 ));
149 add_action('admin_footer', function () {
150 new FeedbackModal();
151 });
152 return;
153 }
154
155 if (!in_array($page_hook, array_values($this->hooks))) {
156 return;
157 }
158 wp_enqueue_style(
159 'superb-addons-admin-dashboard',
160 SUPERBADDONS_ASSETS_PATH . '/css/admin-dashboard.min.css',
161 array(),
162 SUPERBADDONS_VERSION
163 );
164 wp_enqueue_style(
165 'superb-addons-elements',
166 SUPERBADDONS_ASSETS_PATH . '/css/framework.min.css',
167 array(),
168 SUPERBADDONS_VERSION
169 );
170 wp_enqueue_style(
171 'superb-addons-font-manrope',
172 SUPERBADDONS_ASSETS_PATH . '/fonts/manrope/manrope.css',
173 array(),
174 SUPERBADDONS_VERSION
175 );
176
177 if ($page_hook === $this->hooks[self::SUPPORT]) {
178 wp_enqueue_script('superb-addons-troubleshooting', SUPERBADDONS_ASSETS_PATH . '/js/admin/troubleshooting.js', array('jquery', 'wp-i18n'), SUPERBADDONS_VERSION, true);
179 wp_localize_script('superb-addons-troubleshooting', 'superbaddonstroubleshooting_g', array(
180 "rest" => array(
181 "base" => \get_rest_url(),
182 "namespace" => RestController::NAMESPACE,
183 "nonce" => wp_create_nonce("wp_rest"),
184 "routes" => array(
185 "troubleshooting" => TroubleshootingController::TROUBLESHOOTING_ROUTE,
186 "tutorial" => TroubleshootingController::TUTORIAL_ROUTE,
187 )
188 ),
189 "steps" => array(
190 "wordpressversion" => array(
191 "title" => esc_html__("WordPress Version", "superb-blocks"),
192 "text" => esc_html__("Checking Compatibility", "superb-blocks"),
193 "errorText" => esc_html__("Incompatible. Please update WordPress.", "superb-blocks"),
194 "successText" => esc_html__("Compatible", "superb-blocks"),
195 ),
196 "elementorversion" => array(
197 "title" => esc_html__("Elementor Version", "superb-blocks"),
198 "text" => esc_html__("Checking Compatibility", "superb-blocks"),
199 "errorText" => esc_html__("Incompatible. Please install or update Elementor.", "superb-blocks"),
200 "successText" => esc_html__("Compatible", "superb-blocks"),
201 ),
202 "connection" => array(
203 "title" => esc_html__("Connection Status", "superb-blocks"),
204 "text" => esc_html__("Checking Connection", "superb-blocks"),
205 "errorText" => esc_html__("No Connection", "superb-blocks"),
206 "successText" => esc_html__("Connected", "superb-blocks"),
207 ),
208 "domainshift" => array(
209 "title" => esc_html__("Connection Update", "superb-blocks"),
210 "text" => esc_html__("Trying New Connection", "superb-blocks"),
211 "errorText" => esc_html__("Connection Blocked", "superb-blocks"),
212 "successText" => esc_html__("Connected", "superb-blocks"),
213 ),
214 "service" => array(
215 "title" => esc_html__("Service Status", "superb-blocks"),
216 "text" => esc_html__("Checking Service", "superb-blocks"),
217 "errorText" => esc_html__("Service Unavailable", "superb-blocks"),
218 "successText" => esc_html__("Service Online", "superb-blocks"),
219 ),
220 "keycheck" => array(
221 "title" => esc_html__("License Key Status", "superb-blocks"),
222 "text" => esc_html__("Checking License Key", "superb-blocks"),
223 "errorText" => esc_html__("Invalid License Key", "superb-blocks"),
224 "successText" => esc_html__("Valid License Key", "superb-blocks"),
225 ),
226 "keyverify" => array(
227 "title" => esc_html__("License Key Verification", "superb-blocks"),
228 "text" => esc_html__("Re-verifying License Key", "superb-blocks"),
229 "errorText" => esc_html__("License could not be verified", "superb-blocks"),
230 "successText" => esc_html__("License Key Verified", "superb-blocks"),
231 ),
232 "cacheclear" => array(
233 "title" => esc_html__("Cache Status", "superb-blocks"),
234 "text" => esc_html__("Clearing Cache", "superb-blocks"),
235 "errorText" => esc_html__("Cache could not be cleared", "superb-blocks"),
236 "successText" => esc_html__("Cache Cleared", "superb-blocks"),
237 )
238 )
239 ));
240 add_action("admin_footer", array($this, 'TroubleshootingTemplates'));
241 wp_enqueue_style(
242 'superb-addons-admin-modal',
243 SUPERBADDONS_ASSETS_PATH . '/css/admin-modal.min.css',
244 array(),
245 SUPERBADDONS_VERSION
246 );
247 wp_enqueue_style(
248 'superbaddons-js-snackbar',
249 SUPERBADDONS_ASSETS_PATH . '/lib/js-snackbar.min.css',
250 array(),
251 SUPERBADDONS_VERSION
252 );
253 } elseif ($page_hook === $this->hooks[self::SETTINGS]) {
254 wp_enqueue_style(
255 'superb-addons-admin-modal',
256 SUPERBADDONS_ASSETS_PATH . '/css/admin-modal.min.css',
257 array(),
258 SUPERBADDONS_VERSION
259 );
260
261 wp_enqueue_script('superb-addons-settings', SUPERBADDONS_ASSETS_PATH . '/js/admin/settings.js', array('jquery'), SUPERBADDONS_VERSION, true);
262 wp_localize_script('superb-addons-settings', 'superbaddonssettings_g', array(
263 "save_message" => esc_html__("Settings saved successfully.", "superb-blocks"),
264 "modal" => array(
265 "cache" => array(
266 "title" => esc_html__("Clear Cache", "superb-blocks"),
267 "content" => esc_html__("All element- data and images will need to be loaded again if the cache is removed. This should only be done if you are experiencing issues or planning to delete the plugin. Are you sure you want to clear the cache?", "superb-blocks"),
268 "success" => esc_html__("Cache cleared successfully.", "superb-blocks")
269 ),
270 "view_logs" => array(
271 "title" => esc_html__("Error Log", "superb-blocks"),
272 "no_logs" => esc_html__("No errors have been logged.", "superb-blocks"),
273 "icon_unshared" => esc_url(SUPERBADDONS_ASSETS_PATH . "/img/cloud-slash.svg"),
274 "unshared_title" => esc_html__("Error Log Not Shared", "superb-blocks"),
275 "icon_shared" => esc_url(SUPERBADDONS_ASSETS_PATH . "/img/cloud-check.svg"),
276 "shared_title" => esc_html__("Error Log Shared", "superb-blocks"),
277 ),
278 "clear_logs" => array(
279 "title" => esc_html__("Clear Logs", "superb-blocks"),
280 "content" => esc_html__("Error Logs are used for debugging purposes and help improve the plugin when shared with our support team and developers. Are you sure you want to clear the error logs?", "superb-blocks"),
281 "success" => esc_html__("Error logs cleared successfully.", "superb-blocks")
282 ),
283 "remove_key" => array(
284 "title" => esc_html__("Remove License Key", "superb-blocks"),
285 "content" => esc_html__("Are you sure you want to remove your license key from this website?", "superb-blocks"),
286 )
287 ),
288 "rest" => array(
289 "base" => \get_rest_url(),
290 "namespace" => RestController::NAMESPACE,
291 "nonce" => wp_create_nonce("wp_rest"),
292 "routes" => array(
293 "settings" => SettingsController::SETTINGS_ROUTE,
294 )
295 )
296 ));
297 wp_enqueue_style(
298 'superbaddons-js-snackbar',
299 SUPERBADDONS_ASSETS_PATH . '/lib/js-snackbar.min.css',
300 array(),
301 SUPERBADDONS_VERSION
302 );
303 } elseif ($page_hook === $this->hooks[self::ELEMENTOR_DASHBOARD] || $page_hook === $this->hooks[self::GUTENBERG_DASHBOARD]) {
304 $library_loader_file = $page_hook === $this->hooks[self::ELEMENTOR_DASHBOARD] ? 'elementor' : 'gutenberg';
305 $menu_items = $page_hook === $this->hooks[self::ELEMENTOR_DASHBOARD] ? ElementorController::GetElementorLibraryMenuItems() : GutenbergController::GetGutenbergLibraryMenuItems();
306
307
308 wp_enqueue_script('superb-addons-select2', SUPERBADDONS_ASSETS_PATH . '/lib/select2.min.js', array('jquery'), SUPERBADDONS_VERSION, true);
309 wp_enqueue_script('superb-addons-library-dashboard', SUPERBADDONS_ASSETS_PATH . '/js/admin/' . $library_loader_file . '.js', array('jquery'), SUPERBADDONS_VERSION, true);
310 wp_localize_script('superb-addons-library-dashboard', 'superblayoutlibrary_g', array(
311 "style_placeholder" => esc_html__('All themes', "superb-blocks"),
312 "category_placeholder" => esc_html__('All categories', "superb-blocks"),
313 "snacks" => array(
314 "list_error" => esc_html__('Something went wrong while attempting to list elements. Please try again or contact support if the problem persists.', "superb-blocks")
315 ),
316 "menu_items" => $menu_items,
317 "rest" => array(
318 "base" => \get_rest_url(),
319 "namespace" => RestController::NAMESPACE,
320 "nonce" => wp_create_nonce("wp_rest"),
321 "routes" => array(
322 "settings" => SettingsController::SETTINGS_ROUTE,
323 )
324 )
325 ));
326
327 wp_enqueue_style(
328 'superb-elementor-editor-layout-library',
329 SUPERBADDONS_ASSETS_PATH . '/css/layout-library-editor.min.css',
330 array(),
331 SUPERBADDONS_VERSION
332 );
333 wp_enqueue_style(
334 'superbaddons-select2',
335 SUPERBADDONS_ASSETS_PATH . '/lib/select2.min.css',
336 array(),
337 SUPERBADDONS_VERSION
338 );
339 wp_enqueue_style(
340 'superbaddons-js-snackbar',
341 SUPERBADDONS_ASSETS_PATH . '/lib/js-snackbar.min.css',
342 array(),
343 SUPERBADDONS_VERSION
344 );
345 } elseif ($page_hook === $this->hooks[self::ADDITIONAL_CSS]) {
346 wp_enqueue_style(
347 'superb-addons-admin-modal',
348 SUPERBADDONS_ASSETS_PATH . '/css/admin-modal.min.css',
349 array(),
350 SUPERBADDONS_VERSION
351 );
352 wp_enqueue_style(
353 'superbaddons-js-snackbar',
354 SUPERBADDONS_ASSETS_PATH . '/lib/js-snackbar.min.css',
355 array(),
356 SUPERBADDONS_VERSION
357 );
358 wp_enqueue_style(
359 'superbaddons-select2',
360 SUPERBADDONS_ASSETS_PATH . '/lib/select2.min.css',
361 array(),
362 SUPERBADDONS_VERSION
363 );
364
365 do_action('superbaddons/admin/css-blocks/enqueue');
366
367 wp_enqueue_script('superb-addons-select2', SUPERBADDONS_ASSETS_PATH . '/lib/select2.min.js', array('jquery'), SUPERBADDONS_VERSION, true);
368 $code_editor_settings = wp_enqueue_code_editor(array('type' => 'text/css', 'codemirror' => array('lint' => true)));
369 wp_enqueue_script('superb-addons-css-blocks', SUPERBADDONS_ASSETS_PATH . '/js/admin/cssblocks.js', array('jquery', 'wp-i18n'), SUPERBADDONS_VERSION, true);
370 wp_localize_script('superb-addons-css-blocks', 'superbaddonscssblocks_g', array(
371 "codeEditorSettings" => $code_editor_settings,
372 "rest" => array(
373 "base" => \get_rest_url(),
374 "namespace" => RestController::NAMESPACE,
375 "nonce" => wp_create_nonce("wp_rest"),
376 "routes" => array(
377 "css" => CSSController::CSS_ROUTE,
378 ),
379 "error_message" => esc_html__("An error occurred while updating the CSS block. Please try again.", "superb-blocks"),
380 ),
381 ));
382 }
383 }
384
385 public function TroubleshootingTemplates()
386 {
387 ob_start();
388 include(SUPERBADDONS_PLUGIN_DIR . 'src/admin/templates/troubleshooting-step.php');
389 $template = ob_get_clean();
390 echo '<script type="text/template" id="tmpl-superb-addons-troubleshooting-step">' . $template . '</script>';
391 }
392
393 public function SuperbDashboard()
394 {
395 $this->DashboardPageSetup(DashboardPage::class);
396 }
397
398 public function ElementorDashboard()
399 {
400 $this->DashboardPageSetup(ElementorDashboardPage::class);
401 }
402
403 public function GutenbergDashboard()
404 {
405 $this->DashboardPageSetup(GutenbergDashboardPage::class);
406 }
407
408 public function AdditionalCSS()
409 {
410 $this->DashboardPageSetup(AdditionalCSSPage::class);
411 }
412
413 public function Support()
414 {
415 $this->DashboardPageSetup(SupportPage::class);
416 }
417
418 public function Settings()
419 {
420 $this->DashboardPageSetup(SettingsPage::class);
421 }
422
423 private function DashboardPageSetup($page_class)
424 {
425 ?>
426 <div class="superbaddons-wrap">
427 <?php new Navigation(); ?>
428 <div class="superbaddons-wrap-inner">
429 <?php new $page_class(); ?>
430 </div>
431 </div>
432 <?php
433 }
434 }
435