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