| @@ -56,18 +56,47 @@ | ||
| 56 | 56 | // add_action('pxlbsadminify/before/secondary_menu', [$this, 'before_secondary_menu']); |
| 57 | 57 | // } |
| 58 | 58 | |
| 59 | 59 | if (is_admin()) { |
| 60 | - // Switcher for Default UI | |
| 61 | - if (empty($this->adminify_ui)) { | |
| 62 | - if (!empty($this->options['admin_bar_dark_light_btn'])) { | |
| 63 | - add_action('admin_bar_menu', [$this, 'dark_mode_switcher_icon']); | |
| 64 | - } | |
| 60 | + // Light/Dark Mode switcher add | |
| 61 | + if (!empty($this->options['admin_bar_dark_light_btn'])) { | |
| 62 | + add_action('admin_bar_menu', [$this, 'dark_mode_switcher_icon']); | |
| 63 | + // customize.php never fires `admin_enqueue_scripts` - it does not | |
| 64 | + // load admin-header.php - so the switcher's assets have to come in | |
| 65 | + // on the Customizer's own hook. See enqueue_standalone_switcher(). | |
| 66 | + add_action('customize_controls_enqueue_scripts', [$this, 'enqueue_standalone_switcher']); | |
| 65 | 67 | } |
| 68 | + // Add Frontend Site Preview Icon for UI. | |
| 69 | + // Priority 10000: nodes render in the order they are added, and core fills | |
| 70 | + // top-secondary late - my-account at 9991, recovery mode at 9992, search at | |
| 71 | + // 9999 - so anything lower than this lands before them instead of last. | |
| 72 | + if (!empty($this->adminify_ui)) { | |
| 73 | + add_action('admin_bar_menu', [$this, 'preview_icon'], 10000); | |
| 74 | + } | |
| 66 | 75 | } |
| 67 | 76 | } |
| 68 | 77 | |
| 78 | + public function preview_icon($wp_admin_bar) { | |
| 79 | + $args = [ | |
| 80 | + 'parent' => 'top-secondary', | |
| 81 | + 'id' => 'adminify-frontend-site-preview', | |
| 82 | + // Icon only. ab-icon is what WordPress uses to size and align admin bar | |
| 83 | + // glyphs; the label stays for screen readers. | |
| 84 | + 'title' => '<span class="ab-icon dashicons dashicons-visibility" aria-hidden="true"></span><span class="screen-reader-text">' . esc_html__('Preview', 'adminify') . '</span>', | |
| 85 | + 'href' => home_url('/'), | |
| 86 | + 'meta' => [ | |
| 87 | + // Opens the site in a new tab so the admin screen stays put. | |
| 88 | + // noopener keeps the new tab from reaching back via window.opener. | |
| 89 | + 'target' => '_blank', | |
| 90 | + 'rel' => 'noopener', | |
| 91 | + 'title' => esc_attr__('Preview site in a new tab', 'adminify'), | |
| 92 | + ], | |
| 93 | + ]; | |
| 69 | 94 | |
| 95 | + $wp_admin_bar->add_node($args); | |
| 96 | + } | |
| 97 | + | |
| 98 | + | |
| 70 | 99 | // Add Switcher Icon on Admin Bar Secondary |
| 71 | 100 | public function dark_mode_switcher_icon($wp_admin_bar) |
| 72 | 101 | { |
| 73 | 102 | $args = [ |
| @@ -84,9 +113,16 @@ | ||
| 84 | 113 | { |
| 85 | 114 | $global_color_mode = !empty($this->options['light_dark_mode']['admin_ui_mode']) ? $this->options['light_dark_mode']['admin_ui_mode'] : 'light'; |
| 86 | 115 | $color_mode = empty(get_user_meta(get_current_user_id(), 'color_mode', true))? $global_color_mode : get_user_meta(get_current_user_id(), 'color_mode', true); |
| 87 | 116 | |
| 88 | - $color_var = !empty($this->adminify_ui) ? 'var(--adminify-menu-text-color)' : '#fff'; | |
| 117 | + // currentColor, so the glyphs take the colour of whatever bar they land in: | |
| 118 | + // #f0f0f1 from core's `#wpadminbar .ab-empty-item` in the stock admin bar, | |
| 119 | + // and the surrounding text colour inside the dropdown or anywhere Adminify | |
| 120 | + // styles the bar itself. --adminify-menu-text-color was the SIDEBAR's | |
| 121 | + // colour - near-black in light mode, so the icon all but vanished against | |
| 122 | + // the dark admin bar - and it is not even defined on screens where | |
| 123 | + // OutputCSS does not run, customize.php among them. | |
| 124 | + $color_var = 'currentColor'; | |
| 89 | 125 | |
| 90 | 126 | $adminbar_switcher_icon = '<div id="wp-adminify-color-mode-wrapper"> |
| 91 | 127 | <div class="mode-icon adminify-color-mode-' . esc_attr($color_mode) . '-active"> |
| 92 | 128 | <svg viewBox="0 0 24 24" width="24" height="24" class="darkIcon" ><path fill="' . $color_var . '" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg> |
| @@ -271,8 +307,12 @@ | ||
| 271 | 307 | public function admin_scripts() |
| 272 | 308 | { |
| 273 | 309 | global $pagenow; |
| 274 | 310 | if ($pagenow == 'wp-login.php' || $pagenow == 'wp-register.php' || $pagenow == 'customize.php') { |
| 311 | + // Adminify's main bundle is skipped on these screens by design, but | |
| 312 | + // WordPress 7.1 prints the admin bar on customize.php - switcher node | |
| 313 | + // and all. Hand it the standalone assets so it is not left inert. | |
| 314 | + $this->enqueue_standalone_switcher(); | |
| 275 | 315 | return; |
| 276 | 316 | } |
| 277 | 317 | |
| 278 | 318 | // Commented on: 9-6-24 |
| @@ -280,8 +320,46 @@ | ||
| 280 | 320 | wp_enqueue_style('wp-adminify-admin-bar'); |
| 281 | 321 | $this->admin_topbar_loader_css(); |
| 282 | 322 | } |
| 283 | 323 | wp_localize_script('adminify-admin', 'PXLBSADMINIFY_ADMINBAR', $this->create_admin_bar_js_object()); |
| 324 | + } | |
| 325 | + | |
| 326 | + /** | |
| 327 | + * Self-contained Light/Dark/System switcher for screens the main bundle skips. | |
| 328 | + * | |
| 329 | + * `wp-adminify.css` scopes the switcher rules under `.adminify-ui` and | |
| 330 | + * `wp-adminify.js` carries the behaviour, and neither loads on customize.php | |
| 331 | + * (Assets::should_skip_adminify_scripts). WordPress 7.1 renders the admin bar | |
| 332 | + * there, so without this the node paints as bare unstyled SVGs and clicking it | |
| 333 | + * does nothing. Same approach DarkModeConflicts already takes for dark mode. | |
| 334 | + * | |
| 335 | + * Safe to call more than once: wp_enqueue_*() is a no-op on a handle that is | |
| 336 | + * already queued. | |
| 337 | + * | |
| 338 | + * @return void | |
| 339 | + */ | |
| 340 | + public function enqueue_standalone_switcher() | |
| 341 | + { | |
| 342 | + if (empty($this->options['admin_bar_dark_light_btn'])) { | |
| 343 | + return; | |
| 344 | + } | |
| 345 | + | |
| 346 | + wp_enqueue_style( | |
| 347 | + 'adminify-admin-bar-switcher', | |
| 348 | + PXLBSADMINIFY_ASSETS . 'css/wp-adminify-admin-bar-switcher' . Utils::assets_ext('.css'), | |
| 349 | + array(), | |
| 350 | + PXLBSADMINIFY_VER | |
| 351 | + ); | |
| 352 | + | |
| 353 | + wp_enqueue_script( | |
| 354 | + 'adminify-admin-bar-switcher', | |
| 355 | + PXLBSADMINIFY_ASSETS . 'admin/js/wp-adminify-admin-bar-switcher' . Utils::assets_ext('.js'), | |
| 356 | + array(), | |
| 357 | + PXLBSADMINIFY_VER, | |
| 358 | + true | |
| 359 | + ); | |
| 360 | + | |
| 361 | + wp_localize_script('adminify-admin-bar-switcher', 'PXLBSADMINIFY_ADMINBAR', $this->create_admin_bar_js_object()); | |
| 284 | 362 | } |
| 285 | 363 | |
| 286 | 364 | |
| 287 | 365 | public function create_admin_bar_js_object() |