PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.2.6
Adminify – White Label, Admin Menu Editor, Login Customizer v4.2.6
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 4.1.17 All 164 releases
adminify / Inc / Classes / DarkModeConflicts.php

DarkModeConflicts.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.2.6, at Inc/Classes/DarkModeConflicts.php

512 lines 19.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PXLBSAdminify\Inc\Classes;
4
5 use PXLBSAdminify\Inc\Utils;
6 use PXLBSAdminify\Inc\Admin\AdminSettings;
7
8 // no direct access allowed
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12 /**
13 * PXLBSAdminify
14 * Dark Mode Conflicts with other plugins supports
15 *
16 * @author Jewel Theme <support@jeweltheme.com>
17 */
18
19 class DarkModeConflicts
20 {
21 public $options;
22
23 public function __construct()
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'));
38 }
39
40 public function darkmode_scripts()
41 {
42
43 $this->options = (array) AdminSettings::get_instance()->get();
44 $this->options = !empty($this->options['light_dark_mode']['admin_ui_mode']) ? $this->options['light_dark_mode']['admin_ui_mode'] : '';
45
46 if ($this->options == 'light') {
47 return;
48 }
49
50
51 $dark_mode_style = '.ReactModal__Content,
52 .select2-selection,
53 .select2-results__options,
54 .adminify-dark-mode.toplevel_page_aio-contact-lite,
55 .aio-contact-menu,
56 .bsr-action-form input.regular-text,
57 .select2-dropdown,
58 .form-cancel-btn,
59 .folders-tabs,
60 .folder-tab-menu,
61 .folder-tab-menu a,
62 .custom-checkbox span,
63 .preview-inner-box,
64 .preview-inner-box .form-options,
65 .media-buttons,
66 .popup-form-content,
67 .select2-results__option,
68 div.tagsinput,
69 .settings-tabs-list .nav-tab,
70 input[type=number],
71 .bulk-action-select .bulk-action-select__control,
72 .bulk-action-select__menu,
73 .wprf-section-fields,
74 .wprf-section-title,
75 .wprf-input-radio-option:not(.wprf-option-selected) .wprf-input-label,
76 .wprf-control-field .components-button,
77 .wprf-select__menu,
78 .wprf-select__control,
79 .wprf-tab-content,
80 .squirrly-seo-settings #wpcontent .bg-light,
81 .bootstrap-select,
82 .bg-white,
83 .wdt-addons-intro {
84 background: white !important;
85 }
86
87 .el-checkbox.is-checked ~ div,
88 .fluentcrm_header {
89 background: none!important;
90 }
91
92 .folder-user-settings .pro-feature-popup {
93 background: rgb(0, 0, 0, 0.4)
94 }
95
96 .big-pluspro-btn,
97 .dokan-btn,
98 .close_dp_help,
99 .dup-btn,
100 .folder-tab-menu a,
101 .pro-feature-popup .pro-feature-content > a,
102 .user-upgrade-inline-btn,
103 .pro-feature-popup .pro-feature-content .pro-user-title,
104 .pro-feature-popup .pro-feature-content .pro-user-desc,
105 .folder-access,
106 .add-new-folder,
107 .media-select option,
108 .popup-form-content,
109 .nf-button:hover,
110 .wp-react-form h1,
111 .wp-react-form h2,
112 .wp-react-form h3,
113 .wp-react-form h4,
114 .wprf-input-label,
115 .wprf-tab-nav-item:not(:hover),
116 .swift-btn,
117 .wpcode-button,
118 .wdt-constructor-type-selecter-block .card-body h4,
119 .wdt-constructor-type-selecter-block .card-body h4 span,
120 .yoast-button-upsell,
121 .aioseo-button:hover,
122 .el-button {
123 color: white !important;
124 }
125
126 .folders-tabs .dashicons-editor-help,
127 .folder-tab-menu a.active,
128 .folder-list li a span,
129 .select2-selection__rendered,
130 .fp-item-name,
131 .select2-results__option,
132 .form-sample,
133 input[type=number],
134 .wprf-select__single-value,
135 .wprf-code-viewer textarea,
136 .wdt-constructor-type-selecter-block .card-body span,
137 .mce-menu-item > span {
138 color: gray !important;
139 }
140
141 .select2-selection,
142 .bsr-action-form input.regular-text,
143 #bsr-table-select,
144 .custom-checkbox input+span,
145 .preview-inner-box,
146 div.tagsinput,
147 input[type=number],
148 .bulk-action-select .bulk-action-select__control,
149 .wprf-tab-nav-item,
150 .wprf-control-field .components-button,
151 .wprf-select__control,
152 .wprf-control-field input[type="checkbox"],
153 .bootstrap-select {
154 border-color: #D0D5DD !important;
155 }
156
157 .dokan-admin-header-logo img,
158 .dup-header img {
159 filter: grayscale(1) brightness(5);
160 }
161
162 .jetpack-logo,
163 .it-ui-list div[direction="horizontal"] > svg {
164 fill: black !important;
165 }
166
167 .jp-form-block-fade {
168 opacity: 0.5;
169 }
170 ';
171
172 // Elementor Style issues
173 // if (Utils::is_plugin_active('elementor/elementor.php')) {
174 // $dark_mode_style .= '.darkmode{
175 // background: white !important;
176 // }';
177 // }
178
179 // Better Links Style issues
180 if (Utils::is_plugin_active('betterlinks/betterlinks.php')) {
181 $dark_mode_style .= '#betterlinksbody .kpyoXL,
182 .btl-react-select__menu,
183 #betterlinksbody .jlDjrx {
184 background: white !important;
185 }
186 #betterlinksbody .kpyoXL{
187 color: white !important;
188 }
189 ';
190 }
191
192 // Forminator Style issues
193 if (Utils::is_plugin_active('forminator/forminator.php')) {
194 $dark_mode_style .= '.sui-box,
195 .sui-icon-plugin-2,
196 .sui-vertical-tab a.current,
197 .sui-wrap .fui-multi-answers,
198 .sui-wrap .fui-multi-answers .fui-answers>li,
199 .sui-dropdown.open ul,
200 .sui-notice-content,
201 .sui-wrap .sui-box-selectors,
202 .sui-select-dropdown,
203 .sui-accordion-item,
204 .sui-tabs-menu,
205 .forminator-addon-card--footer,
206 .sui-vertical-tab.current,
207 .sui-form-control,
208 select#forminator-field-user_role,
209 .forminator-save-field-settings {
210 background: white !important;
211 }
212
213 .sui-upgrade-page,
214 .sui-upgrade-page-header,
215 .sui-upgrade-page-cta {
216 background: none!important;
217 }
218
219 .sui-header-title,
220 .sui-summary-large,
221 .sui-list-label,
222 .sui-box-title,
223 .sui-wrap h1,
224 .sui-wrap h2,
225 .sui-wrap h3,
226 .sui-button,
227 .sui-vertical-tab a.current,
228 .sui-table thead>tr>th,
229 .sui-trim-text,
230 .sui-message-content h2,
231 .sui-tab-item.active,
232 .sui-vertical-tab.current a,
233 select#forminator-field-user_role {
234 color: white !important;
235 }
236
237 .sui-upsell-list li,
238 .sui-table-item-title,
239 .sui-vertical-tab a,
240 .sui-form-control,
241 .sui-settings-label {
242 color: gray !important;
243 }
244
245 .sui-list li,
246 .sui-box-header,
247 #sui-cross-sell-footer>div,
248 .sui-box-settings-row,
249 .sui-dropdown.open ul,
250 .sui-box-footer,
251 .sui-status-changes,
252 .sui-table thead>tr>th,
253 .sui-select-dropdown,
254 .sui-tab-content,
255 .forminator-addon-card--footer,
256 .sui-table.fui-table--apps,
257 .sui-table tbody>tr>td,
258 .sui-tabs-overflow,
259 .sui-form-control,
260 .sui-button,
261 select#forminator-field-user_role {
262 border-color: #D0D5DD !important;
263 }
264
265 .sui-dropdown.open ul::after,
266 .sui-dropdown.open ul::before {
267 border-color: #D0D5DD rgba(0, 0, 0, 0)!important;
268 }
269
270 .sui-box,
271 .sui-accordion-item,
272 .sui-tabs-menu {
273 box-shadow: none!important;
274 }
275
276 .sui-chartjs-message--empty {
277 background-blend-mode: exclusion;
278 }
279
280 .sui-tag,
281 .sui-tabs-menu .sui-tab-item {
282 background: #6f6f6f!important;
283 color: #fff!important;
284 }
285
286 .sui-tab-item.active {
287 background: black!important;
288 }
289 ';
290 }
291
292 // Loginpress
293 if (Utils::is_plugin_active('loginpress/loginpress.php')) {
294 $dark_mode_style .= '.loginpress-help-page pre textarea,
295 .loginpress-import-export-page .upload-file,
296 .loginpress-extension {
297 background: white !important;
298 }
299
300 .toplevel_page_loginpress-settings #wpcontent,
301 .loginpress_page_loginpress-help #wpcontent,
302 .loginpress_page_loginpress-import-export #wpcontent,
303 .loginpress-header-wrapper,
304 .loginpress-settings {
305 background: none!important;
306 }
307
308 .loginpress-help-page h2,
309 .loginpress-import-export-page h2,
310 .loginpress-addons-wrap h2,
311 .loginpress-extension h3 span,
312 .loginpress-settings h3{
313 color: white !important;
314 }
315
316 .loginpress-help-page pre textarea,
317 .loginpress-import-export-page > div,
318 .loginpress-settings .form-table tr th,
319 .loginpress-settings .form-table tr td fieldset label {
320 color: gray !important
321 }
322
323 .loginpress-help-page pre textarea,
324 .loginpress-import-export-page .upload-file,
325 .loginpress-extension h3,
326 .loginpress-extension {
327 border-color: #D0D5DD !important;
328 }
329
330 .loginpress-header-logo img {
331 filter: grayscale(1) brightness(5);
332 }
333
334 ';
335 }
336
337 // Notificationx Style issues
338 if (Utils::is_plugin_active('notificationx/notificationx.php')) {
339 $dark_mode_style .= '.nx-analytics-counter,
340 #notificationx .notificationx-items .nx-admin-menu>ul li:not(.nx-active) a,
341 .nx-admin-sidebar .sidebar-widget,
342 .nx-settings-right,
343 .nx-admin-block,
344 .nx-sidebar,
345 .nx-quick-builder-wrapper {
346 background: white !important;
347 }
348
349 .nx-button:not(:hover) {
350 background: none!important;
351 }
352
353 .nx-counter-number,
354 .nx-admin-title {
355 color: white !important;
356 }
357
358 #notificationx .notificationx-items .nx-admin-menu>ul li:not(.nx-active) a,
359 #nx-title,
360 #notification-template,
361 .nx-admin-sidebar-cta a:not(:hover) {
362 color: gray !important;
363 }
364
365 #notificationx .notificationx-items .nx-admin-menu>ul li:not(.nx-active) a,
366 #nx-title,
367 .nx-widget-title,
368 #notification-template {
369 border-color: #D0D5DD !important;
370 }
371
372 .nx-admin-sidebar-logo img {
373 filter: grayscale(1) brightness(5);
374 }
375
376 .nx-admin-header svg g {
377 fill: #fff!important;
378 }
379 ';
380 }
381
382 // Wpdatatables Style issues
383 if (Utils::is_plugin_active('wpdatatables/wpdatatables.php')) {
384 $dark_mode_style .= '.wpdt-c.toplevel_page_wpdatatables-dashboard,
385 .wpdt-c .wdt-datatables-admin-wrap .plugin-dashboard,
386 .wpdt-c.wpdatatables_page_wpdatatables-administration,
387 .card-header.wdt-admin-card-header.ch-alt,
388 #wdt-datatables-browse-table,
389 .manage-column,
390 .wpdt-c.wpdatatables_page_wpdatatables-constructor,
391 .wdt-constructor-type-selecter-block .card-header,
392 .wpdt-c,
393 .chart-wizard-breadcrumb,
394 .wpdt-c .chart-name,
395 .wpdt-c .render-engine {
396 background: white !important;
397 }
398
399 ';
400 }
401
402
403
404 $dark_mode_style = preg_replace('#/\*.*?\*/#s', '', $dark_mode_style);
405 $dark_mode_style = preg_replace('/\s*([{}|:;,])\s+/', '$1', $dark_mode_style);
406 $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);
510 }
511 }
512