PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.49
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.49
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / admin / shared / dark-theme.php

dark-theme.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.49, at includes/admin/shared/dark-theme.php

551 lines 16.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shared Dark Theme Support for King Addons Admin Pages
4 *
5 * Include this file at the top of admin pages to add dark theme support.
6 * Usage: include KING_ADDONS_PATH . 'includes/admin/shared/dark-theme.php';
7 *
8 * @package King_Addons
9 */
10
11 if (!defined('ABSPATH')) {
12 exit;
13 }
14
15 // Ensure V3 segmented control styles are available wherever this helper is used.
16 wp_enqueue_style(
17 'king-addons-admin-v3',
18 KING_ADDONS_URL . 'includes/admin/layouts/shared/admin-v3-styles.css',
19 [],
20 KING_ADDONS_VERSION
21 );
22
23 // Theme mode is per-user. Must be global so functions can access it.
24 global $ka_theme_mode;
25 $ka_theme_mode = get_user_meta(get_current_user_id(), 'king_addons_theme_mode', true);
26 $ka_allowed_theme_modes = ['dark', 'light', 'auto'];
27 if (!in_array($ka_theme_mode, $ka_allowed_theme_modes, true)) {
28 $ka_theme_mode = 'dark';
29 }
30
31 /**
32 * Output the dark theme toggle HTML
33 */
34 function ka_render_dark_theme_toggle() {
35 global $ka_theme_mode;
36 ?>
37 <div class="ka-v3-segmented" id="ka-v3-theme-segment" role="radiogroup" aria-label="<?php echo esc_attr(esc_html__('Theme', 'king-addons')); ?>" data-active="<?php echo esc_attr($ka_theme_mode); ?>">
38 <span class="ka-v3-segmented-indicator" aria-hidden="true"></span>
39 <button type="button" class="ka-v3-segmented-btn" data-theme="light" aria-pressed="<?php echo $ka_theme_mode === 'light' ? 'true' : 'false'; ?>">
40 <span class="ka-v3-segmented-icon" aria-hidden="true">☀︎</span>
41 <?php esc_html_e('Light', 'king-addons'); ?>
42 </button>
43 <button type="button" class="ka-v3-segmented-btn" data-theme="dark" aria-pressed="<?php echo $ka_theme_mode === 'dark' ? 'true' : 'false'; ?>">
44 <span class="ka-v3-segmented-icon" aria-hidden="true"></span>
45 <?php esc_html_e('Dark', 'king-addons'); ?>
46 </button>
47 <button type="button" class="ka-v3-segmented-btn" data-theme="auto" aria-pressed="<?php echo $ka_theme_mode === 'auto' ? 'true' : 'false'; ?>">
48 <?php esc_html_e('Auto', 'king-addons'); ?>
49 </button>
50 </div>
51 <?php
52 }
53
54 /**
55 * Output the dark theme CSS
56 */
57 function ka_render_dark_theme_styles() {
58 ?>
59 <style>
60 /* Theme Switch Button */
61 .ka-theme-switch {
62 display: flex;
63 align-items: center;
64 }
65 .ka-theme-toggle {
66 background: none;
67 border: none;
68 padding: 0;
69 cursor: pointer;
70 display: flex;
71 align-items: center;
72 }
73 .ka-theme-switch-track {
74 width: 52px;
75 height: 28px;
76 background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
77 border-radius: 14px;
78 position: relative;
79 transition: background 0.3s ease;
80 display: flex;
81 align-items: center;
82 justify-content: space-between;
83 padding: 0 6px;
84 }
85 .ka-theme-switch-track::before,
86 .ka-theme-switch-track::after {
87 font-size: 12px;
88 opacity: 0.7;
89 }
90 .ka-theme-switch-thumb {
91 position: absolute;
92 top: 2px;
93 left: 2px;
94 width: 24px;
95 height: 24px;
96 background: #fff;
97 border-radius: 50%;
98 transition: transform 0.3s ease, background 0.3s ease;
99 display: flex;
100 align-items: center;
101 justify-content: center;
102 box-shadow: 0 2px 4px rgba(0,0,0,0.2);
103 }
104 .ka-theme-switch-thumb::before {
105 content: '';
106 position: absolute;
107 top: 50%;
108 left: 50%;
109 transform: translate(-50%, -50%);
110 }
111 .ka-theme-switch-thumb .ka-sun-icon {
112 color: #f59e0b;
113 display: flex;
114 transition: opacity 0.2s ease;
115 }
116 .ka-theme-switch-thumb .ka-moon-icon {
117 color: #6366f1;
118 display: none;
119 transition: opacity 0.2s ease;
120 }
121 .ka-theme-switch-track:hover {
122 box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
123 }
124
125 /* Dark theme switch state */
126 .ka-dark-theme .ka-theme-switch-track {
127 background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
128 }
129 .ka-dark-theme .ka-theme-switch-track::before,
130 .ka-dark-theme .ka-theme-switch-track::after {
131 color: #fff;
132 }
133 .ka-dark-theme .ka-theme-switch-thumb {
134 transform: translateX(24px);
135 background: #1e1b4b;
136 }
137 .ka-dark-theme .ka-theme-switch-thumb::before {
138 color: #c7d2fe;
139 }
140 .ka-dark-theme .ka-theme-switch-thumb .ka-sun-icon {
141 display: none;
142 }
143 .ka-dark-theme .ka-theme-switch-thumb .ka-moon-icon {
144 display: flex;
145 color: #c7d2fe;
146 }
147 .ka-dark-theme .ka-theme-switch-track:hover {
148 box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
149 }
150
151 /* Instant theme switch (no transition) */
152 .ka-no-transition,
153 .ka-no-transition * {
154 transition: none !important;
155 }
156
157 /* ========================================
158 DARK THEME STYLES
159 ======================================== */
160
161 /* WordPress admin background */
162 body.ka-dark-theme #wpcontent,
163 body.ka-dark-theme #wpbody,
164 body.ka-dark-theme #wpbody-content {
165 background: #0f172a;
166 }
167
168 /* Main wrappers */
169 .ka-dark-theme .ka-settings-wrap,
170 .ka-dark-theme .ka-cookie-wrap,
171 .ka-dark-theme .ka-agegate-wrap,
172 .ka-dark-theme .ka-ai-wrap,
173 .ka-dark-theme .ka-wishlist-wrap,
174 .ka-dark-theme .ka-analytics-wrap,
175 .ka-dark-theme .ka-security-wrap,
176 .ka-dark-theme .ka-woo-wrap {
177 background: #0f172a;
178 }
179
180 /* Headers - keep gradients but adjust */
181 .ka-dark-theme .ka-settings-header,
182 .ka-dark-theme .ka-cookie-header,
183 .ka-dark-theme .ka-agegate-header,
184 .ka-dark-theme .ka-ai-header,
185 .ka-dark-theme .ka-wishlist-header,
186 .ka-dark-theme .ka-analytics-header,
187 .ka-dark-theme .ka-security-header,
188 .ka-dark-theme .ka-woo-header {
189 box-shadow: 0 4px 20px rgba(0,0,0,0.3);
190 }
191
192 /* Cards */
193 .ka-dark-theme .ka-card,
194 .ka-dark-theme .ka-section,
195 .ka-dark-theme .ka-stat-card,
196 .ka-dark-theme .ka-stats-card {
197 background: #1e293b;
198 border-color: #334155;
199 box-shadow: 0 1px 3px rgba(0,0,0,0.3);
200 }
201 .ka-dark-theme .ka-card-header,
202 .ka-dark-theme .ka-section-header {
203 background: #1e293b;
204 border-bottom-color: #334155;
205 }
206 .ka-dark-theme .ka-card-header h2,
207 .ka-dark-theme .ka-section-header h2,
208 .ka-dark-theme .ka-card-header h3,
209 .ka-dark-theme .ka-section-title {
210 color: #f1f5f9;
211 }
212 .ka-dark-theme .ka-card-body,
213 .ka-dark-theme .ka-section-body {
214 background: #1e293b;
215 }
216
217 /* Form elements */
218 .ka-dark-theme .ka-row {
219 border-bottom-color: #334155;
220 }
221 .ka-dark-theme .ka-row-label,
222 .ka-dark-theme label {
223 color: #cbd5e1;
224 }
225 .ka-dark-theme .ka-row-desc,
226 .ka-dark-theme .ka-field-desc,
227 .ka-dark-theme .description {
228 color: #94a3b8;
229 }
230 .ka-dark-theme .ka-row-field input[type="text"],
231 .ka-dark-theme .ka-row-field input[type="number"],
232 .ka-dark-theme .ka-row-field input[type="password"],
233 .ka-dark-theme .ka-row-field input[type="email"],
234 .ka-dark-theme .ka-row-field input[type="url"],
235 .ka-dark-theme .ka-row-field textarea,
236 .ka-dark-theme .ka-row-field select,
237 .ka-dark-theme input[type="text"],
238 .ka-dark-theme input[type="number"],
239 .ka-dark-theme input[type="password"],
240 .ka-dark-theme input[type="email"],
241 .ka-dark-theme input[type="url"],
242 .ka-dark-theme textarea,
243 .ka-dark-theme select {
244 background: #0f172a;
245 border-color: #475569;
246 color: #f1f5f9;
247 }
248 .ka-dark-theme .ka-row-field input:focus,
249 .ka-dark-theme input:focus,
250 .ka-dark-theme textarea:focus,
251 .ka-dark-theme select:focus {
252 border-color: #6366f1;
253 box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
254 }
255 .ka-dark-theme input::placeholder,
256 .ka-dark-theme textarea::placeholder {
257 color: #64748b;
258 }
259
260 /* Toggles */
261 .ka-dark-theme .ka-toggle-slider {
262 background: #475569;
263 }
264 .ka-dark-theme .ka-toggle input:checked + .ka-toggle-slider {
265 background: #6366f1;
266 }
267
268 /* Tabs */
269 .ka-dark-theme .ka-tabs {
270 background: #1e293b;
271 }
272 .ka-dark-theme .ka-tab {
273 color: #94a3b8;
274 background: transparent;
275 }
276 .ka-dark-theme .ka-tab:hover {
277 background: #334155;
278 color: #f1f5f9;
279 }
280 .ka-dark-theme .ka-tab.active {
281 background: #6366f1;
282 color: #fff;
283 }
284
285 /* Tables */
286 .ka-dark-theme table {
287 background: #1e293b;
288 border-color: #334155;
289 }
290 .ka-dark-theme th {
291 background: #0f172a;
292 color: #f1f5f9;
293 border-color: #334155;
294 }
295 .ka-dark-theme td {
296 color: #cbd5e1;
297 border-color: #334155;
298 }
299 .ka-dark-theme tr:hover td {
300 background: #334155;
301 }
302
303 /* Buttons */
304 .ka-dark-theme .button {
305 background: #334155;
306 border-color: #475569;
307 color: #f1f5f9;
308 transition: all 0.2s;
309 }
310 .ka-dark-theme .button:hover {
311 background: #475569;
312 border-color: #6366f1;
313 color: #fff;
314 }
315 .ka-dark-theme .button-primary,
316 .ka-dark-theme .ka-btn-primary {
317 background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
318 border: none;
319 color: #fff;
320 transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
321 }
322 .ka-dark-theme .button-primary:hover,
323 .ka-dark-theme .ka-btn-primary:hover {
324 background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
325 color: #fff;
326 transform: translateY(-1px);
327 box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
328 }
329
330 /* Submit area */
331 .ka-dark-theme .ka-submit,
332 .ka-dark-theme .ka-card-footer {
333 background: #0f172a;
334 border-top-color: #334155;
335 }
336
337 /* Status badges */
338 .ka-dark-theme .ka-status-enabled {
339 background: rgba(34, 197, 94, 0.2);
340 color: #4ade80;
341 }
342 .ka-dark-theme .ka-status-disabled {
343 background: rgba(239, 68, 68, 0.2);
344 color: #f87171;
345 }
346
347 /* Text colors */
348 .ka-dark-theme h1, .ka-dark-theme h2, .ka-dark-theme h3, .ka-dark-theme h4 {
349 color: #f1f5f9;
350 }
351 .ka-dark-theme p, .ka-dark-theme span, .ka-dark-theme div {
352 color: #cbd5e1;
353 }
354 .ka-dark-theme a {
355 color: #818cf8;
356 }
357 .ka-dark-theme a:hover {
358 color: #a5b4fc;
359 }
360
361 .ka-dark-theme a.ka-wb-dropdown-item{
362 color: var(--ka-wb-text);
363 }
364
365 .ka-dark-theme a.ka-wb-dropdown-item.is-danger {
366 color: #ff3b30;
367 }
368
369 /* Stat cards */
370 .ka-dark-theme .ka-stat-value,
371 .ka-dark-theme .ka-stat-number {
372 color: #f1f5f9;
373 }
374 .ka-dark-theme .ka-stat-label {
375 color: #94a3b8;
376 }
377 .ka-dark-theme .ka-stat-icon {
378 background: rgba(99, 102, 241, 0.2);
379 }
380
381 /* Code/Pre */
382 .ka-dark-theme code,
383 .ka-dark-theme pre {
384 background: #0f172a;
385 color: #e2e8f0;
386 border-color: #334155;
387 }
388
389 /* Notices */
390 .ka-dark-theme .ka-notice,
391 .ka-dark-theme .notice {
392 background: #1e293b;
393 border-color: #475569;
394 color: #cbd5e1;
395 }
396
397 /* Specific page adjustments */
398 .ka-dark-theme .ka-log-entry {
399 background: #0f172a;
400 border-color: #334155;
401 }
402
403 /* WooCommerce Builder specific */
404 .ka-dark-theme .ka-woo-grid .ka-woo-card {
405 background: #1e293b;
406 border-color: #334155;
407 }
408 .ka-dark-theme .ka-woo-card:hover {
409 border-color: #6366f1;
410 }
411 .ka-dark-theme .ka-woo-card-title {
412 color: #f1f5f9;
413 }
414 .ka-dark-theme .ka-woo-card-desc {
415 color: #94a3b8;
416 }
417
418 /* Filter bar */
419 .ka-dark-theme .ka-filter-bar {
420 background: #1e293b;
421 border-color: #334155;
422 }
423
424 /* Scrollbar */
425 .ka-dark-theme ::-webkit-scrollbar {
426 width: 8px;
427 height: 8px;
428 }
429 .ka-dark-theme ::-webkit-scrollbar-track {
430 background: #1e293b;
431 }
432 .ka-dark-theme ::-webkit-scrollbar-thumb {
433 background: #475569;
434 border-radius: 4px;
435 }
436 .ka-dark-theme ::-webkit-scrollbar-thumb:hover {
437 background: #64748b;
438 }
439 </style>
440 <?php
441 }
442
443 /**
444 * Output the dark theme JavaScript
445 */
446 function ka_render_dark_theme_script() {
447 ?>
448 <script>
449 (function($) {
450 'use strict';
451
452 // AJAX settings
453 const ajaxUrl = '<?php echo esc_url(admin_url('admin-ajax.php')); ?>';
454 const nonce = '<?php echo esc_js(wp_create_nonce('king_addons_dashboard_ui')); ?>';
455
456 // Save UI setting via AJAX
457 function saveUISetting(key, value) {
458 $.post(ajaxUrl, {
459 action: 'king_addons_save_dashboard_ui',
460 nonce: nonce,
461 key: key,
462 value: value
463 });
464 }
465
466 const themeMql = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null;
467 let themeMode = ($('#ka-v3-theme-segment').attr('data-active') || 'dark').toString();
468 let themeMqlHandler = null;
469
470 function applyThemeClasses(isDark) {
471 if (isDark) {
472 $('body').addClass('ka-dark-theme');
473 } else {
474 $('body').removeClass('ka-dark-theme');
475 }
476
477 $('body').toggleClass('ka-v3-dark', isDark);
478 document.documentElement.classList.toggle('ka-v3-dark', isDark);
479 }
480
481 function updateSegment(mode) {
482 var $segment = $('#ka-v3-theme-segment');
483 if (!$segment.length) {
484 return;
485 }
486 $segment.attr('data-active', mode);
487 $segment.find('.ka-v3-segmented-btn').each(function() {
488 var theme = $(this).data('theme');
489 $(this).attr('aria-pressed', theme === mode ? 'true' : 'false');
490 });
491 }
492
493 function setThemeMode(mode, save) {
494 themeMode = mode;
495 updateSegment(mode);
496
497 if (themeMqlHandler && themeMql) {
498 if (themeMql.removeEventListener) {
499 themeMql.removeEventListener('change', themeMqlHandler);
500 } else if (themeMql.removeListener) {
501 themeMql.removeListener(themeMqlHandler);
502 }
503 themeMqlHandler = null;
504 }
505
506 if (mode === 'auto') {
507 applyThemeClasses(!!(themeMql && themeMql.matches));
508 themeMqlHandler = function(e) {
509 if (themeMode !== 'auto') {
510 return;
511 }
512 applyThemeClasses(!!e.matches);
513 };
514 if (themeMql) {
515 if (themeMql.addEventListener) {
516 themeMql.addEventListener('change', themeMqlHandler);
517 } else if (themeMql.addListener) {
518 themeMql.addListener(themeMqlHandler);
519 }
520 }
521 } else {
522 applyThemeClasses(mode === 'dark');
523 }
524
525 if (save) {
526 saveUISetting('theme_mode', mode);
527 }
528 }
529
530 // Theme segmented control click
531 $(document).on('click', '#ka-v3-theme-segment .ka-v3-segmented-btn', function(e) {
532 e.preventDefault();
533 setThemeMode(($(this).data('theme') || 'dark').toString(), true);
534 });
535
536 // Apply current mode (incl. Auto listener)
537 setThemeMode(themeMode, false);
538 })(jQuery);
539 </script>
540 <?php
541 }
542
543 /**
544 * Output inline script to apply dark theme immediately (before page renders)
545 */
546 function ka_render_dark_theme_init() {
547 global $ka_theme_mode;
548 $mode = esc_js($ka_theme_mode);
549 echo '<script>(function(){var mode="' . $mode . '";var mql=window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)"):null;function apply(isDark){document.documentElement.classList.toggle("ka-v3-dark",!!isDark);if(document.body){document.body.classList.toggle("ka-v3-dark",!!isDark);document.body.classList.toggle("ka-dark-theme",!!isDark);}}function ensureBody(fn){if(document.body){fn();return;}document.addEventListener("DOMContentLoaded",fn,{once:true});}if(mode==="auto"){var isDark=!!(mql&&mql.matches);apply(isDark);ensureBody(function(){apply(isDark);});}else{var dark=(mode==="dark");apply(dark);ensureBody(function(){apply(dark);});}})();</script>';
550 }
551