| @@ -17,13 +17,12 @@ | ||
| 17 | 17 | public $adminify_ui; |
| 18 | 18 | |
| 19 | 19 | public function __construct() |
| 20 | 20 | { |
| 21 | - $this->options = (array) AdminSettings::get_instance()->get(); | |
| 22 | - $this->adminify_ui = Utils::check_modules($this->options['admin_ui']); | |
| 21 | + $this->options = (array) AdminSettings::get_instance()->get(); | |
| 22 | + $this->adminify_ui = Utils::check_modules($this->options['admin_ui']); | |
| 23 | 23 | |
| 24 | - add_action('admin_enqueue_scripts', [$this, 'admin_ui_preset_vars_enqueue']); | |
| 25 | - add_action('admin_head', [$this, 'admin_ui_preset_vars_styles']); | |
| 24 | + add_action('admin_head', [$this, 'admin_ui_preset_vars_styles']); | |
| 26 | 25 | } |
| 27 | 26 | |
| 28 | 27 | |
| 29 | 28 | /** |
| @@ -435,76 +434,67 @@ | ||
| 435 | 434 | |
| 436 | 435 | return $light_logo_css . $dark_logo_css; |
| 437 | 436 | } |
| 438 | 437 | |
| 439 | - | |
| 440 | 438 | /** |
| 441 | - * Enqueue scripts for admin UI preset vars | |
| 439 | + * Output styles in admin_head to avoid headers already sent issues | |
| 442 | 440 | */ |
| 443 | - public function admin_ui_preset_vars_enqueue() { | |
| 441 | + public function admin_ui_preset_vars_styles() { | |
| 444 | 442 | global $pagenow; |
| 445 | - if ($pagenow == 'wp-login.php' || $pagenow == 'wp-register.php' || $pagenow == 'customize.php') { | |
| 443 | + | |
| 444 | + // 1. Handle pages where get_current_screen() doesn't exist | |
| 445 | + $auth_pages = ['wp-login.php', 'wp-signup.php', 'wp-activate.php']; | |
| 446 | + if (in_array($pagenow, $auth_pages)) { | |
| 446 | 447 | return; |
| 447 | 448 | } |
| 448 | - | |
| 449 | - // CSS for Adminify UI | |
| 450 | - if (!empty($this->options['admin_ui'])) { | |
| 451 | - wp_enqueue_script('adminify-theme-presetter', PXLBSADMINIFY_ASSETS . 'admin/js/wp-adminify-theme-presetter.js', ['jquery'], PXLBSADMINIFY_VER, true); | |
| 452 | - wp_localize_script('adminify-theme-presetter', 'PXLBSADMINIFY_PRESET_THEMES', Utils::get_theme_presets()); | |
| 453 | - } | |
| 454 | - } | |
| 455 | - | |
| 456 | - /** | |
| 457 | - * Output styles in admin_head to avoid headers already sent issues | |
| 458 | - */ | |
| 459 | - public function admin_ui_preset_vars_styles() { | |
| 460 | - global $pagenow; | |
| 461 | - if ($pagenow == 'wp-login.php' || $pagenow == 'wp-register.php' || $pagenow == 'customize.php') { | |
| 449 | + | |
| 450 | + // 2. Handle customize.php | |
| 451 | + if ($pagenow === 'customize.php') { | |
| 462 | 452 | return; |
| 463 | 453 | } |
| 464 | 454 | |
| 465 | - // CSS for Adminify UI | |
| 466 | - if (!empty($this->options['admin_ui'])) { | |
| 467 | - if (array_key_exists('adminify_theme', $this->options) && !empty($this->options['adminify_theme'])) { | |
| 468 | - $theme = $this->options['adminify_theme']; | |
| 469 | - } else { | |
| 470 | - $theme = 'preset1'; // get the default value dynamically | |
| 471 | - } | |
| 455 | + // CSS for Adminify UI | |
| 456 | + if (!empty($this->options['admin_ui'])) { | |
| 457 | + if (array_key_exists('adminify_theme', $this->options) && !empty($this->options['adminify_theme'])) { | |
| 458 | + $theme = $this->options['adminify_theme']; | |
| 459 | + } else { | |
| 460 | + $theme = 'preset1'; // get the default value dynamically | |
| 461 | + } | |
| 472 | 462 | |
| 473 | - $preset = (array) Utils::get_theme_presets($theme); | |
| 463 | + $preset = (array) Utils::get_theme_presets($theme); | |
| 474 | 464 | |
| 475 | - // Dynamic Css Variables Array | |
| 476 | - $css_var = $this->output_styles(); | |
| 465 | + // Dynamic Css Variables Array | |
| 466 | + $css_var = $this->output_styles(); | |
| 477 | 467 | |
| 478 | - $preset_style = ''; | |
| 468 | + $preset_style = ''; | |
| 479 | 469 | |
| 480 | - foreach ($preset as $prop => $val) { | |
| 481 | - // Check Duplicate Array | |
| 482 | - if( !array_key_exists($prop, $css_var) ) { | |
| 483 | - $preset_style .= sprintf('%s:%s;', esc_attr($prop), esc_attr($val)); | |
| 470 | + foreach ($preset as $prop => $val) { | |
| 471 | + // Check Duplicate Array | |
| 472 | + if( !array_key_exists($prop, $css_var) ) { | |
| 473 | + $preset_style .= sprintf('%s:%s;', esc_attr($prop), esc_attr($val)); | |
| 474 | + } | |
| 484 | 475 | } |
| 485 | - } | |
| 486 | 476 | |
| 487 | - foreach ($css_var as $prop => $val) { | |
| 488 | - $preset_style .= sprintf('%s:%s;', esc_attr($prop), esc_attr($val)); | |
| 489 | - } | |
| 477 | + foreach ($css_var as $prop => $val) { | |
| 478 | + $preset_style .= sprintf('%s:%s;', esc_attr($prop), esc_attr($val)); | |
| 479 | + } | |
| 490 | 480 | |
| 491 | - if (empty($preset_style)) { | |
| 492 | - return; | |
| 493 | - } | |
| 481 | + if (empty($preset_style)) { | |
| 482 | + return; | |
| 483 | + } | |
| 494 | 484 | |
| 495 | - // Text Logo styles | |
| 496 | - // if($this->options['light_dark_mode']['admin_ui_logo_type'] === 'text_logo') { | |
| 497 | - // // $text_logo_css = $this->logo_text_styles(); | |
| 485 | + // Text Logo styles | |
| 486 | + // if($this->options['light_dark_mode']['admin_ui_logo_type'] === 'text_logo') { | |
| 487 | + // // $text_logo_css = $this->logo_text_styles(); | |
| 498 | 488 | |
| 499 | - // if(!empty($text_logo_css)) { | |
| 500 | - // printf('<style id="adminify_text_logo">body.adminify-ui{%s}</style>', wp_strip_all_tags($text_logo_css)); | |
| 501 | - // } | |
| 502 | - // } | |
| 489 | + // if(!empty($text_logo_css)) { | |
| 490 | + // printf('<style id="adminify_text_logo">body.adminify-ui{%s}</style>', wp_strip_all_tags($text_logo_css)); | |
| 491 | + // } | |
| 492 | + // } | |
| 503 | 493 | |
| 504 | - printf('<style>body.wp-adminify{%s}</style>', esc_html( wp_strip_all_tags($preset_style) )); | |
| 505 | - } else { | |
| 506 | - printf('<style>body.wp-adminify{%s}</style>', esc_html( wp_strip_all_tags( $this->output_styles()) )); | |
| 507 | - } | |
| 494 | + printf('<style>body.wp-adminify{%s}</style>', esc_html( wp_strip_all_tags($preset_style) )); | |
| 495 | + } else { | |
| 496 | + printf('<style>body.wp-adminify{%s}</style>', esc_html( wp_strip_all_tags( $this->output_styles()) )); | |
| 497 | + } | |
| 508 | 498 | |
| 509 | 499 | } |
| 510 | 500 | } |