PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0.5.4
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0.5.4
4.3.2 4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 All 165 releases
← All changes | Inc/Classes/DarkModeConflicts.php +7 -121 4.2.64.0.5.4 View file →
@@ -1,10 +1,10 @@
1 1 <?php
2 2
3 -namespace PXLBSAdminify\Inc\Classes;
3 +namespace WPAdminify\Inc\Classes;
4 4
5 -use PXLBSAdminify\Inc\Utils;
6 -use PXLBSAdminify\Inc\Admin\AdminSettings;
5 +use WPAdminify\Inc\Utils;
6 +use WPAdminify\Inc\Admin\AdminSettings;
7 7
8 8 // no direct access allowed
9 9 if (!defined('ABSPATH')) {
10 10 exit;
@@ -9,9 +9,9 @@
9 9 if (!defined('ABSPATH')) {
10 10 exit;
11 11 }
12 12 /**
13 - * PXLBSAdminify
13 + * WPAdminify
14 14 * Dark Mode Conflicts with other plugins supports
15 15 *
16 16 * @author Jewel Theme <support@jeweltheme.com>
17 17 */
@@ -21,24 +21,12 @@
21 21 public $options;
22 22
23 23 public function __construct()
24 24 {
25 - add_action('admin_enqueue_scripts', array($this, 'darkmode_scripts'), 100);
26 - add_action( 'enqueue_block_editor_assets', array($this, "gutenberg_block_editor_darkmode_assets"));
27 - // WP 6.3+/7.0: the block editor canvas runs in an iframe. The AdminifyDarkMode
28 - // script has no built-in iframe support, so inject the same script INTO the
29 - // iframe and call .enable() from inside — that way Darkreader runs over the
30 - // iframe DOM the same dynamic way it runs on the parent admin.
31 - // Use admin_footer (not enqueue_block_editor_assets — wp_add_inline_script
32 - // silently dropped the bridge) and direct-print via wp_print_inline_script_tag.
33 - add_action('admin_footer', array($this, 'inject_darkmode_into_editor_iframe'), 999);
34 - // customize.php controls: Adminify scripts are skipped there by design
35 - // (Assets::should_skip_adminify_scripts), so enqueue dark-mode only on this
36 - // dedicated hook to keep the customize panel dark without the rest of Adminify.
37 - add_action('customize_controls_enqueue_scripts', array($this, 'customize_controls_darkmode_enqueue'));
25 + add_action('admin_enqueue_scripts', array($this, 'jltwp_adminify_darkmode_scripts'), 100);
38 26 }
39 27
40 - public function darkmode_scripts()
28 + public function jltwp_adminify_darkmode_scripts()
41 29 {
42 30
43 31 $this->options = (array) AdminSettings::get_instance()->get();
44 32 $this->options = !empty($this->options['light_dark_mode']['admin_ui_mode']) ? $this->options['light_dark_mode']['admin_ui_mode'] : '';
@@ -403,109 +391,7 @@
403 391
404 392 $dark_mode_style = preg_replace('#/\*.*?\*/#s', '', $dark_mode_style);
405 393 $dark_mode_style = preg_replace('/\s*([{}|:;,])\s+/', '$1', $dark_mode_style);
406 394 $dark_mode_style = preg_replace('/\s\s+(.*)/', '$1', $dark_mode_style);
407 - wp_add_inline_style('adminify-admin', wp_strip_all_tags($dark_mode_style));
408 - }
409 -
410 - /**
411 - * Gutenberg Block Editor Dark Mode CSS
412 - */
413 - function gutenberg_block_editor_darkmode_assets () {
414 -
415 - wp_register_style('adminify-gutenberg-dark', false, array(), PXLBSADMINIFY_VER);
416 - wp_enqueue_style('adminify-gutenberg-dark');
417 -
418 - // $parent_selector = 'body.wp-adminify.adminify-dark-mode';
419 - $parent_selector = 'body.wp-adminify';
420 -
421 - $dark_mode_style = "$parent_selector .components-modal__content .components-text,
422 - $parent_selector .components-popover__content .components-text { color: black!important; }
423 - $parent_selector .block-editor-block-inspector .components-tools-panel { border-top-color: #e0e0e0; }
424 - $parent_selector .admin-ui-navigable-region .components-panel__header > div > button { color: black; }
425 - $parent_selector .editor-sidebar__panel .editor-post-card-panel__header svg,
426 - $parent_selector .commands-command-menu__container .commands-command-menu__header svg { fill: black; }
427 - ";
428 - wp_add_inline_style('adminify-gutenberg-dark', wp_strip_all_tags($dark_mode_style));
429 - }
430 -
431 - /**
432 - * Resolve the active light/dark mode for the current user.
433 - * Per-user `color_mode` meta takes precedence over the global setting.
434 - * Returns 'light' | 'dark' | 'auto' | ''.
435 - */
436 - public function pxlbsadminify_resolve_color_mode()
437 - {
438 - $opts = (array) AdminSettings::get_instance()->get();
439 - $global_mode = !empty($opts['light_dark_mode']['admin_ui_mode']) ? $opts['light_dark_mode']['admin_ui_mode'] : 'light';
440 - $user_mode = get_user_meta(get_current_user_id(), 'color_mode', true);
441 - return !empty($user_mode) ? $user_mode : $global_mode;
442 - }
443 -
444 - /**
445 - * Inject the AdminifyDarkMode script INTO the WP 6.3+/7.0 block editor iframe
446 - * canvas. The script attaches a global `window.AdminifyDarkMode` and uses a
447 - * Darkreader-style dynamic theme that rewrites colors based on the running
448 - * document — so it must be loaded inside the iframe's window to darken the
449 - * canvas DOM, not just the parent admin chrome.
450 - *
451 - * The bridge below watches for `iframe[name="editor-canvas"]` (added/changed
452 - * across edits or full-site editor route changes), injects the dark-mode JS
453 - * into the iframe's document, and calls `AdminifyDarkMode.enable()` once it
454 - * loads. `__adminifyDarkInjected` guards against double-injection.
455 - */
456 - public function inject_darkmode_into_editor_iframe()
457 - {
458 - if ( $this->pxlbsadminify_resolve_color_mode() !== 'dark' ) {
459 - return;
460 - }
461 - // Only run on block-editor pages (post.php / post-new.php / site editor).
462 - $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
463 - if ( ! $screen || ! method_exists( $screen, 'is_block_editor' ) || ! $screen->is_block_editor() ) {
464 - // also accept Site Editor screen ids
465 - $is_site_editor = $screen && in_array( $screen->id, array( 'site-editor', 'gutenberg_page_gutenberg-edit-site' ), true );
466 - if ( ! $is_site_editor ) {
467 - return;
468 - }
469 - }
470 - $dark_js_url = PXLBSADMINIFY_ASSETS . 'admin/js/wp-adminify-dark-mode' . Utils::assets_ext( '.js' );
471 - $bridge = '(function(){'
472 - . 'var URL=' . wp_json_encode( $dark_js_url ) . ';'
473 - . 'function looksLikeEditor(ifr){try{if(ifr.name==="editor-canvas")return true;var d=ifr.contentDocument;return !!(d&&d.body&&d.body.classList&&(d.body.classList.contains("block-editor-iframe__body")||d.body.classList.contains("editor-styles-wrapper")));}catch(e){return false;}}'
474 - . 'function activate(w){try{if(w&&w.AdminifyDarkMode){w.AdminifyDarkMode.enable({brightness:120});return true;}}catch(e){}return false;}'
475 - . 'function inject(ifr){try{var d=ifr.contentDocument,w=ifr.contentWindow;if(!d||!w)return;if(w.__adminifyDM){activate(w);return;}w.__adminifyDM=true;if(activate(w))return;var s=d.createElement("script");s.src=URL;s.onload=function(){if(!activate(w)){setTimeout(function(){activate(w);},100);setTimeout(function(){activate(w);},500);}};(d.head||d.documentElement||d.body).appendChild(s);}catch(e){}}'
476 - . 'var seen=new WeakSet();'
477 - . 'function watch(ifr){if(seen.has(ifr))return;seen.add(ifr);inject(ifr);ifr.addEventListener("load",function(){try{ifr.contentWindow.__adminifyDM=false;}catch(e){}inject(ifr);});}'
478 - . 'function scan(){var all=document.querySelectorAll("iframe");for(var i=0;i<all.length;i++){if(looksLikeEditor(all[i]))watch(all[i]);}}'
479 - . 'if(document.readyState!=="loading"){scan();}else{document.addEventListener("DOMContentLoaded",scan);}'
480 - . 'new MutationObserver(scan).observe(document.documentElement,{childList:true,subtree:true});'
481 - . '}());';
482 - if ( function_exists( 'wp_print_inline_script_tag' ) ) {
483 - wp_print_inline_script_tag( $bridge );
484 - } else {
485 - echo '<script>' . $bridge . '</script>'; // phpcs:ignore WordPress.WP.EnqueuedResources
486 - }
487 - return; // sentinel — never reach legacy enqueue path below
488 - }
489 -
490 - /**
491 - * customize.php controls: Adminify's general scripts are deliberately skipped on
492 - * customize.php (Assets::should_skip_adminify_scripts), so dark-mode never reaches
493 - * the controls panel. Enqueue dark-mode standalone on the customize controls hook.
494 - */
495 - public function customize_controls_darkmode_enqueue()
496 - {
497 - if ($this->pxlbsadminify_resolve_color_mode() !== 'dark') {
498 - return;
499 - }
500 - wp_enqueue_script(
501 - 'adminify--dark-mode',
502 - PXLBSADMINIFY_ASSETS . 'admin/js/wp-adminify-dark-mode' . Utils::assets_ext('.js'),
503 - array(),
504 - PXLBSADMINIFY_VER,
505 - false
506 - );
507 - $inline = 'if(window.AdminifyDarkMode){window.AdminifyDarkMode.enable({brightness:120});}'
508 - . 'addEventListener("load",function(){if(window.AdminifyDarkMode){window.AdminifyDarkMode.enable({brightness:120});}});';
509 - wp_add_inline_script('adminify--dark-mode', $inline);
395 + wp_add_inline_style('wp-adminify-admin', wp_strip_all_tags($dark_mode_style));
510 396 }
511 397 }