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