PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 2.0.3
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v2.0.3
2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 All 57 releases
darkify / src / Frontend / Templates / header_script.php

header_script.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 2.0.3, at src/Frontend/Templates/header_script.php

446 lines 39.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use ThemeAtelier\Darkify\Includes\DarkifyUtils;
4
5 // don't call the file directly.
6 if (!defined('ABSPATH')) {
7 exit;
8 }
9
10 ob_start();
11 $options = get_option('darkify');
12 // Controls
13 $enable_default_dark_mode = isset($options['enable_default_dark_mode']) ? $options['enable_default_dark_mode'] : '';
14 $enable_os_aware = isset($options['enable_os_aware']) ? $options['enable_os_aware'] : true;
15 $enable_keyboard_shortcut = isset($options['enable_keyboard_shortcut']) ? $options['enable_keyboard_shortcut'] : true;
16 $keyboard_shortcut_keys = isset($options['keyboard_shortcut_keys']) && $options['keyboard_shortcut_keys'] ? $options['keyboard_shortcut_keys'] : 'ctrl+alt+d';
17 $enable_time = isset($options['enable_time']) ? $options['enable_time'] : "";
18 $enable_time_based_dark = isset($enable_time['enable_time_based_dark']) ? $enable_time['enable_time_based_dark'] : "";
19 $enable_time_fields = isset($enable_time['enable_time_fields']) ? $enable_time['enable_time_fields'] : '';
20 $time_based_dark_start = isset($enable_time_fields['time_based_dark_start']) ? $enable_time_fields['time_based_dark_start'] : "";
21 $time_based_dark_stop = isset($enable_time_fields['time_based_dark_end']) ? $enable_time_fields['time_based_dark_end'] : "";
22
23 // Extras
24 $enable_scrollbar_dark = isset($options["enable_scrollbar_dark"]) ? $options["enable_scrollbar_dark"] : true;
25 $enable_frontend_iframe_dark_mode = isset($options['enable_frontend_iframe_dark_mode']) ? $options['enable_frontend_iframe_dark_mode'] : true;
26 $enable_switch_dragging = isset($options['enable_switch_dragging']) ? $options['enable_switch_dragging'] : "";
27 $enable_switch_attention = isset($options['enable_switch_attention']) ? $options['enable_switch_attention'] : '';
28 $switch_attention_effect = isset($options['switch_attention_effect']) ? $options['switch_attention_effect'] : 'pulse';
29 $disallowed_elements = isset($options['disallowed_elements']) ? DarkifyUtils::normalize_restriction_class($options['disallowed_elements']) : "";
30
31 $disallowed_elements_force_to_correct = isset($options['disallowed_elements_force_to_correct']) ? $options['disallowed_elements_force_to_correct'] : true;
32 $allowed_elements_force_to_correct = isset($options['allowed_elements_force_to_correct']) ? $options['allowed_elements_force_to_correct'] : true;
33 $allowed_elements = isset($options['allowed_elements']) ? DarkifyUtils::normalize_restriction_class($options['allowed_elements']) : "";
34
35 $alternative_dark_mode_switcher = isset($options['alternative_dark_mode_switcher']) ? $options['alternative_dark_mode_switcher'] : "";
36
37
38 // Image Control
39 $brightness = isset($options['brightness']) ? $options['brightness'] : "";
40 $enable_low_image_brightness = isset($brightness['enable_low_image_brightness']) ? $brightness['enable_low_image_brightness'] : '1';
41 $low_image_brightness_label = isset($brightness['low_image_brightness_label']) ? 100 - $brightness['low_image_brightness_label'] : 100 - "20";
42 $disallowed_low_brightness_images = isset($brightness['disallowed_low_brightness_images']) ? DarkifyUtils::normalize_image_urls($brightness['disallowed_low_brightness_images']) : "";
43
44 $grayscale = isset($options['grayscale']) ? $options['grayscale'] : "";
45 $enable_image_grayscale = isset($grayscale['enable_image_grayscale']) ? $grayscale['enable_image_grayscale'] : "";
46 $image_grayscale_label = isset($grayscale['image_grayscale_label']) ? $grayscale['image_grayscale_label'] : "80";
47 $disallowed_low_grayscale_images = isset($grayscale['disallowed_low_grayscale_images']) ? DarkifyUtils::normalize_image_urls($grayscale['disallowed_low_grayscale_images']) : "";
48
49 $darken_background = isset($options['darken_background']) ? $options['darken_background'] : "";
50 $enable_low_image_darken = isset($darken_background['enable_low_image_darken']) ? $darken_background['enable_low_image_darken'] : "1";
51 $low_image_darken_label = isset($darken_background['low_image_darken_label']) ? $darken_background['low_image_darken_label'] : '60';
52
53 $enable_invert_inline_svg = isset($options['enable_invert_inline_svg']) ? $options['enable_invert_inline_svg'] : "";
54
55 // Adaptive colour layer — gradients, brand colours, shadows.
56 $darkify_gradient_handling = isset($options['gradient_handling']) ? $options['gradient_handling'] : 'recolor';
57 $darkify_shadow_handling = isset($options['shadow_handling']) ? $options['shadow_handling'] : 'neutralize';
58 $darkify_brand_color_handling = isset($options['brand_color_handling']) ? $options['brand_color_handling'] : 'adaptive';
59
60 // Anything not on these lists came from somewhere other than the settings UI,
61 // so it falls back to the shipped default rather than reaching the engine.
62 $darkify_gradient_handling = in_array($darkify_gradient_handling, array('recolor', 'flatten', 'keep'), true) ? $darkify_gradient_handling : 'recolor';
63 $darkify_shadow_handling = in_array($darkify_shadow_handling, array('neutralize', 'map', 'remove', 'keep'), true) ? $darkify_shadow_handling : 'neutralize';
64 $darkify_brand_color_handling = in_array($darkify_brand_color_handling, array('flatten', 'adaptive'), true) ? $darkify_brand_color_handling : 'adaptive';
65
66 /*
67 * The override rows are printed into a <script> as raw JSON (like
68 * darkify_allowed_btn_class below), so each value is reduced to a known-safe
69 * shape here: a hex colour or one of the fixed scope keys. Rows missing either
70 * colour are dropped — a half-filled repeater row is the default state of the
71 * field and means nothing to the engine.
72 */
73 $darkify_color_overrides = array();
74 if (!empty($options['color_overrides']) && is_array($options['color_overrides'])) {
75 $darkify_override_scopes = array('all', 'text', 'icon', 'background', 'border', 'shadow');
76 foreach ($options['color_overrides'] as $darkify_override_row) {
77 if (!is_array($darkify_override_row)) {
78 continue;
79 }
80
81 $darkify_light = isset($darkify_override_row['light_color']) ? sanitize_hex_color($darkify_override_row['light_color']) : '';
82 $darkify_dark = isset($darkify_override_row['dark_color']) ? sanitize_hex_color($darkify_override_row['dark_color']) : '';
83
84 if (!$darkify_light || !$darkify_dark) {
85 continue;
86 }
87
88 $darkify_scope = isset($darkify_override_row['override_scope']) ? $darkify_override_row['override_scope'] : 'all';
89 if (!in_array($darkify_scope, $darkify_override_scopes, true)) {
90 $darkify_scope = 'all';
91 }
92
93 $darkify_color_overrides[] = array(
94 'light_color' => $darkify_light,
95 'dark_color' => $darkify_dark,
96 'override_scope' => $darkify_scope,
97 );
98 }
99 }
100
101 $invert = isset($options['invert']) ? $options['invert'] : "";
102 $enable_invert_images = isset($invert['enable_invert_images']) ? $invert['enable_invert_images'] : "";
103 $invert_images_allowed_urls = !empty($invert['invert_images_allowed_urls']) ? DarkifyUtils::normalize_image_urls($invert['invert_images_allowed_urls']) : "";
104
105 if ($invert_images_allowed_urls !== "") {
106 $invert_images_allowed_urls_explode = explode(',', $invert_images_allowed_urls);
107 $invert_images_allowed_urls_arr = json_encode($invert_images_allowed_urls_explode);
108 } else {
109 $invert_images_allowed_urls_arr = "[]";
110 }
111
112 $normal_image_replacements = isset($options["image_replacements"][0]['normal_image']) ? $options["image_replacements"][0]['normal_image'] : '';
113 $dark_image_replacements = isset($options["image_replacements"][0]['dark_image']) ? $options["image_replacements"][0]['dark_image'] : '';
114 if ($normal_image_replacements || $dark_image_replacements) {
115 $image_replacements = json_encode($options["image_replacements"]);
116 } else {
117 $image_replacements = "";
118 }
119
120 // Video Control
121 $video_brightness = isset($options['video_brightness']) ? $options['video_brightness'] : "";
122 $enable_low_video_brightness = isset($video_brightness['enable_low_video_brightness']) ? $video_brightness['enable_low_video_brightness'] : true;
123 $low_video_brightness_label = isset($video_brightness['low_video_brightness_label']) ? 100 - $video_brightness['low_video_brightness_label'] : 100 - "20";
124
125 $video_grayscale = isset($options['video_grayscale']) ? $options['video_grayscale'] : '';
126 $enable_video_grayscale = isset($video_grayscale['enable_video_grayscale']) ? $video_grayscale['enable_video_grayscale'] : "";
127 $video_grayscale_label = isset($video_grayscale['video_grayscale_label']) ? $video_grayscale['video_grayscale_label'] : "80";
128
129 $normal_video_replacements = isset($options["video_replacements"][0]["normal_video"]) ? $options["video_replacements"][0]["normal_video"] : '';
130 $dark_video_replacements = isset($options["video_replacements"][0]["dark_video"]) ? $options["video_replacements"][0]["dark_video"] : '';
131 if ($normal_video_replacements || $dark_video_replacements) {
132 $video_replacements = json_encode($options["video_replacements"]);
133 } else {
134 $video_replacements = "[]";
135 }
136 if (!is_admin()) { ?>
137 <script type="text/javascript" class="darkify_inline_js">(function(){var s=localStorage.darkify_last_state,t=localStorage.darkify_selected_theme||'set1';if(s==='1'){var h=document.documentElement;h.classList.add('darkify_dark_mode_enabled');h.classList.add('darkify-'+t);h.classList.add('darkify_prepaint');setTimeout(function(){h.classList.remove('darkify_prepaint')},800);}}());</script>
138 <style type="text/css" class="darkify_inline_css">
139 :root {
140 <?php
141 $dark_mode_color_palettes = [
142 'set1' => [
143 'bg' => isset($options["dark_mode_color_set1"]) ? $options["dark_mode_color_set1"]['background'] : '#0F0F0F',
144 'secondary_bg' => isset($options["dark_mode_color_set1"]) ? $options["dark_mode_color_set1"]['secondary_background'] : '#171717',
145 'text_color' => isset($options["dark_mode_link_color_set1"]) ? $options["dark_mode_link_color_set1"]['text'] : '#BEBEBE',
146 'link_color' => isset($options["dark_mode_link_color_set1"]) ? $options["dark_mode_link_color_set1"]['color'] : '#E7E7E7',
147 'link_hover_color' => isset($options["dark_mode_link_color_set1"]) ? $options["dark_mode_link_color_set1"]['hover'] : '#BEBEBE',
148 'input_bg' => isset($options["dark_mode_input_color_set1"]) ? $options["dark_mode_input_color_set1"]['background'] : '#2D2D2D',
149 'input_text_color' => isset($options["dark_mode_input_color_set1"]) ? $options["dark_mode_input_color_set1"]['color'] : '#BEBEBE',
150 'input_placeholder_color' => isset($options["dark_mode_input_color_set1"]) ? $options["dark_mode_input_color_set1"]['placeholder'] : '#BEBEBE',
151 'border_color' => isset($options["dark_mode_border_color_set1"]) ? $options["dark_mode_border_color_set1"] : '#4A4A4A',
152 'btn_text_color' => isset($options["dark_mode_btn_color_set1"]) ? $options["dark_mode_btn_color_set1"]['color'] : '#BEBEBE',
153 'btn_bg' => isset($options["dark_mode_btn_color_set1"]) ? $options["dark_mode_btn_color_set1"]['background'] : '#4A4A4A',
154 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set1"]) ? $options["dark_mode_btn_color_set1"]['hover_color'] : '#BEBEBE',
155 'btn_hover_bg' => isset($options["dark_mode_btn_color_set1"]) ? $options["dark_mode_btn_color_set1"]['hover_background'] : '#2D2D2D',
156 ],
157 'set2' => [
158 'bg' => isset($options["dark_mode_color_set2"]) ? $options["dark_mode_color_set2"]['background'] : '#092635',
159 'secondary_bg' => isset($options["dark_mode_color_set2"]) ? $options["dark_mode_color_set2"]['secondary_background'] : '#081E29',
160 'text_color' => isset($options["dark_mode_link_color_set2"]) ? $options["dark_mode_link_color_set2"]['text'] : '#BEE0F1',
161 'link_color' => isset($options["dark_mode_link_color_set2"]) ? $options["dark_mode_link_color_set2"]['color'] : '#2B97CD',
162 'link_hover_color' => isset($options["dark_mode_link_color_set2"]) ? $options["dark_mode_link_color_set2"]['hover'] : '#BEE0F1',
163 'input_bg' => isset($options["dark_mode_input_color_set2"]) ? $options["dark_mode_input_color_set2"]['background'] : '#2D2D2D',
164 'input_text_color' => isset($options["dark_mode_input_color_set2"]) ? $options["dark_mode_input_color_set2"]['color'] : '#BEE0F1',
165 'input_placeholder_color' => isset($options["dark_mode_input_color_set2"]) ? $options["dark_mode_input_color_set2"]['placeholder'] : '#BEE0F1',
166 'border_color' => isset($options["dark_mode_border_color_set2"]) ? $options["dark_mode_border_color_set2"] : '#195979',
167 'btn_text_color' => isset($options["dark_mode_btn_color_set2"]) ? $options["dark_mode_btn_color_set2"]['color'] : '#BEE0F1',
168 'btn_bg' => isset($options["dark_mode_btn_color_set2"]) ? $options["dark_mode_btn_color_set2"]['background'] : '#195979',
169 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set2"]) ? $options["dark_mode_btn_color_set2"]['hover_color'] : '#BEE0F1',
170 'btn_hover_bg' => isset($options["dark_mode_btn_color_set2"]) ? $options["dark_mode_btn_color_set2"]['hover_background'] : '#2D2D2D',
171 ],
172 'set3' => [
173 'bg' => isset($options["dark_mode_color_set3"]) ? $options["dark_mode_color_set3"]['background'] : '#211e3c',
174 'secondary_bg' => isset($options["dark_mode_color_set3"]) ? $options["dark_mode_color_set3"]['secondary_background'] : '#302C57',
175 'text_color' => isset($options["dark_mode_link_color_set3"]) ? $options["dark_mode_link_color_set3"]['text'] : '#B1BBD8',
176 'link_color' => isset($options["dark_mode_link_color_set3"]) ? $options["dark_mode_link_color_set3"]['color'] : '#8071fb',
177 'link_hover_color' => isset($options["dark_mode_link_color_set3"]) ? $options["dark_mode_link_color_set3"]['hover'] : '#B1BBD8',
178 'input_bg' => isset($options["dark_mode_input_color_set3"]) ? $options["dark_mode_input_color_set3"]['background'] : '#2A264D',
179 'input_text_color' => isset($options["dark_mode_input_color_set3"]) ? $options["dark_mode_input_color_set3"]['color'] : '#B1BBD8',
180 'input_placeholder_color' => isset($options["dark_mode_input_color_set3"]) ? $options["dark_mode_input_color_set3"]['placeholder'] : '#B1BBD8',
181 'border_color' => isset($options["dark_mode_border_color_set3"]) ? $options["dark_mode_border_color_set3"] : '#4E478D',
182 'btn_text_color' => isset($options["dark_mode_btn_color_set3"]) ? $options["dark_mode_btn_color_set3"]['color'] : '#B1BBD8',
183 'btn_bg' => isset($options["dark_mode_btn_color_set3"]) ? $options["dark_mode_btn_color_set3"]['background'] : '#4E478D',
184 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set3"]) ? $options["dark_mode_btn_color_set3"]['hover_color'] : '#B1BBD8',
185 'btn_hover_bg' => isset($options["dark_mode_btn_color_set3"]) ? $options["dark_mode_btn_color_set3"]['hover_background'] : '#2A264D',
186 ],
187 'set4' => [
188 'bg' => isset($options["dark_mode_color_set4"]) ? $options["dark_mode_color_set4"]['background'] : '#1d253a',
189 'secondary_bg' => isset($options["dark_mode_color_set4"]) ? $options["dark_mode_color_set4"]['secondary_background'] : '#2B3655',
190 'text_color' => isset($options["dark_mode_link_color_set4"]) ? $options["dark_mode_link_color_set4"]['text'] : '#B1BBD8',
191 'link_color' => isset($options["dark_mode_link_color_set4"]) ? $options["dark_mode_link_color_set4"]['color'] : '#638eff',
192 'link_hover_color' => isset($options["dark_mode_link_color_set4"]) ? $options["dark_mode_link_color_set4"]['hover'] : '#B1BBD8',
193 'input_bg' => isset($options["dark_mode_input_color_set4"]) ? $options["dark_mode_input_color_set4"]['background'] : '#242F4C',
194 'input_text_color' => isset($options["dark_mode_input_color_set4"]) ? $options["dark_mode_input_color_set4"]['color'] : '#B1BBD8',
195 'input_placeholder_color' => isset($options["dark_mode_input_color_set4"]) ? $options["dark_mode_input_color_set4"]['placeholder'] : '#B1BBD8',
196 'border_color' => isset($options["dark_mode_border_color_set4"]) ? $options["dark_mode_border_color_set4"] : '#46598C',
197 'btn_text_color' => isset($options["dark_mode_btn_color_set4"]) ? $options["dark_mode_btn_color_set4"]['color'] : '#B1BBD8',
198 'btn_bg' => isset($options["dark_mode_btn_color_set4"]) ? $options["dark_mode_btn_color_set4"]['background'] : '#46598C',
199 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set4"]) ? $options["dark_mode_btn_color_set4"]['hover_color'] : '#B1BBD8',
200 'btn_hover_bg' => isset($options["dark_mode_btn_color_set4"]) ? $options["dark_mode_btn_color_set4"]['hover_background'] : '#303D60',
201 ],
202 'set5' => [
203 'bg' => isset($options["dark_mode_color_set5"]) ? $options["dark_mode_color_set5"]['background'] : '#1b1823',
204 'secondary_bg' => isset($options["dark_mode_color_set5"]) ? $options["dark_mode_color_set5"]['secondary_background'] : '#352f44',
205 'text_color' => isset($options["dark_mode_link_color_set5"]) ? $options["dark_mode_link_color_set5"]['text'] : '#C6C1D5',
206 'link_color' => isset($options["dark_mode_link_color_set5"]) ? $options["dark_mode_link_color_set5"]['color'] : '#b094ff',
207 'link_hover_color' => isset($options["dark_mode_link_color_set5"]) ? $options["dark_mode_link_color_set5"]['hover'] : '#C6C1D5',
208 'input_bg' => isset($options["dark_mode_input_color_set5"]) ? $options["dark_mode_input_color_set5"]['background'] : '#403953',
209 'input_text_color' => isset($options["dark_mode_input_color_set5"]) ? $options["dark_mode_input_color_set5"]['color'] : '#C6C1D5',
210 'input_placeholder_color' => isset($options["dark_mode_input_color_set5"]) ? $options["dark_mode_input_color_set5"]['placeholder'] : '#C6C1D5',
211 'border_color' => isset($options["dark_mode_border_color_set5"]) ? $options["dark_mode_border_color_set5"] : '#54496f',
212 'btn_text_color' => isset($options["dark_mode_btn_color_set5"]) ? $options["dark_mode_btn_color_set5"]['color'] : '#C6C1D5',
213 'btn_bg' => isset($options["dark_mode_btn_color_set5"]) ? $options["dark_mode_btn_color_set5"]['background'] : '#54496f',
214 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set5"]) ? $options["dark_mode_btn_color_set5"]['hover_color'] : '#C6C1D5',
215 'btn_hover_bg' => isset($options["dark_mode_btn_color_set5"]) ? $options["dark_mode_btn_color_set5"]['hover_background'] : '#403953',
216 ],
217 'set6' => [
218 'bg' => isset($options["dark_mode_color_set6"]) ? $options["dark_mode_color_set6"]['background'] : '#082032',
219 'secondary_bg' => isset($options["dark_mode_color_set6"]) ? $options["dark_mode_color_set6"]['secondary_background'] : '#061825',
220 'text_color' => isset($options["dark_mode_link_color_set6"]) ? $options["dark_mode_link_color_set6"]['text'] : '#B5D9F3',
221 'link_color' => isset($options["dark_mode_link_color_set6"]) ? $options["dark_mode_link_color_set6"]['color'] : '#61bbff',
222 'link_hover_color' => isset($options["dark_mode_link_color_set6"]) ? $options["dark_mode_link_color_set6"]['hover'] : '#B5D9F3',
223 'input_bg' => isset($options["dark_mode_input_color_set6"]) ? $options["dark_mode_input_color_set6"]['background'] : '#0E3755',
224 'input_text_color' => isset($options["dark_mode_input_color_set6"]) ? $options["dark_mode_input_color_set6"]['color'] : '#B5D9F3',
225 'input_placeholder_color' => isset($options["dark_mode_input_color_set6"]) ? $options["dark_mode_input_color_set6"]['placeholder'] : '#B5D9F3',
226 'border_color' => isset($options["dark_mode_border_color_set6"]) ? $options["dark_mode_border_color_set6"] : '#144E78',
227 'btn_text_color' => isset($options["dark_mode_btn_color_set6"]) ? $options["dark_mode_btn_color_set6"]['color'] : '#B5D9F3',
228 'btn_bg' => isset($options["dark_mode_btn_color_set6"]) ? $options["dark_mode_btn_color_set6"]['background'] : '#144E78',
229 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set6"]) ? $options["dark_mode_btn_color_set6"]['hover_color'] : '#B5D9F3',
230 'btn_hover_bg' => isset($options["dark_mode_btn_color_set6"]) ? $options["dark_mode_btn_color_set6"]['hover_background'] : '#0E3755',
231 ],
232 'set7' => [
233 'bg' => isset($options["dark_mode_color_set7"]) ? $options["dark_mode_color_set7"]['background'] : '#07161b',
234 'secondary_bg' => isset($options["dark_mode_color_set7"]) ? $options["dark_mode_color_set7"]['secondary_background'] : '#0d242e',
235 'text_color' => isset($options["dark_mode_link_color_set7"]) ? $options["dark_mode_link_color_set7"]['text'] : '#C5E6F0',
236 'link_color' => isset($options["dark_mode_link_color_set7"]) ? $options["dark_mode_link_color_set7"]['color'] : '#33c0ec',
237 'link_hover_color' => isset($options["dark_mode_link_color_set7"]) ? $options["dark_mode_link_color_set7"]['hover'] : '#C5E6F0',
238 'input_bg' => isset($options["dark_mode_input_color_set7"]) ? $options["dark_mode_input_color_set7"]['background'] : '#19495A',
239 'input_text_color' => isset($options["dark_mode_input_color_set7"]) ? $options["dark_mode_input_color_set7"]['color'] : '#C5E6F0',
240 'input_placeholder_color' => isset($options["dark_mode_input_color_set7"]) ? $options["dark_mode_input_color_set7"]['placeholder'] : '#C5E6F0',
241 'border_color' => isset($options["dark_mode_border_color_set7"]) ? $options["dark_mode_border_color_set7"] : '#286F8D',
242 'btn_text_color' => isset($options["dark_mode_btn_color_set7"]) ? $options["dark_mode_btn_color_set7"]['color'] : '#C5E6F0',
243 'btn_bg' => isset($options["dark_mode_btn_color_set7"]) ? $options["dark_mode_btn_color_set7"]['background'] : '#286F8D',
244 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set7"]) ? $options["dark_mode_btn_color_set7"]['hover_color'] : '#C5E6F0',
245 'btn_hover_bg' => isset($options["dark_mode_btn_color_set7"]) ? $options["dark_mode_btn_color_set7"]['hover_background'] : '#19495A',
246 ],
247 'set8' => [
248 'bg' => isset($options["dark_mode_color_set8"]) ? $options["dark_mode_color_set8"]['background'] : '#15274C',
249 'secondary_bg' => isset($options["dark_mode_color_set8"]) ? $options["dark_mode_color_set8"]['secondary_background'] : '#112244',
250 'text_color' => isset($options["dark_mode_link_color_set8"]) ? $options["dark_mode_link_color_set8"]['text'] : '#ACC1EA',
251 'link_color' => isset($options["dark_mode_link_color_set8"]) ? $options["dark_mode_link_color_set8"]['color'] : '#6197ff',
252 'link_hover_color' => isset($options["dark_mode_link_color_set8"]) ? $options["dark_mode_link_color_set8"]['hover'] : '#ACC1EA',
253 'input_bg' => isset($options["dark_mode_input_color_set8"]) ? $options["dark_mode_input_color_set8"]['background'] : '#1a2f5c',
254 'input_text_color' => isset($options["dark_mode_input_color_set8"]) ? $options["dark_mode_input_color_set8"]['color'] : '#ACC1EA',
255 'input_placeholder_color' => isset($options["dark_mode_input_color_set8"]) ? $options["dark_mode_input_color_set8"]['placeholder'] : '#ACC1EA',
256 'border_color' => isset($options["dark_mode_border_color_set8"]) ? $options["dark_mode_border_color_set8"] : '#244892',
257 'btn_text_color' => isset($options["dark_mode_btn_color_set8"]) ? $options["dark_mode_btn_color_set8"]['color'] : '#ACC1EA',
258 'btn_bg' => isset($options["dark_mode_btn_color_set8"]) ? $options["dark_mode_btn_color_set8"]['background'] : '#244892',
259 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set8"]) ? $options["dark_mode_btn_color_set8"]['hover_color'] : '#ACC1EA',
260 'btn_hover_bg' => isset($options["dark_mode_btn_color_set8"]) ? $options["dark_mode_btn_color_set8"]['hover_background'] : '#1a2f5c',
261 ],
262 'set9' => [
263 'bg' => isset($options["dark_mode_color_set9"]) ? $options["dark_mode_color_set9"]['background'] : '#04261d',
264 'secondary_bg' => isset($options["dark_mode_color_set9"]) ? $options["dark_mode_color_set9"]['secondary_background'] : '#021e16',
265 'text_color' => isset($options["dark_mode_link_color_set9"]) ? $options["dark_mode_link_color_set9"]['text'] : '#C1D2BB',
266 'link_color' => isset($options["dark_mode_link_color_set9"]) ? $options["dark_mode_link_color_set9"]['color'] : '#00d29a',
267 'link_hover_color' => isset($options["dark_mode_link_color_set9"]) ? $options["dark_mode_link_color_set9"]['hover'] : '#C1D2BB',
268 'input_bg' => isset($options["dark_mode_input_color_set9"]) ? $options["dark_mode_input_color_set9"]['background'] : '#073d2f',
269 'input_text_color' => isset($options["dark_mode_input_color_set9"]) ? $options["dark_mode_input_color_set9"]['color'] : '#C1D2BB',
270 'input_placeholder_color' => isset($options["dark_mode_input_color_set9"]) ? $options["dark_mode_input_color_set9"]['placeholder'] : '#C1D2BB',
271 'border_color' => isset($options["dark_mode_border_color_set9"]) ? $options["dark_mode_border_color_set9"] : '#095541',
272 'btn_text_color' => isset($options["dark_mode_btn_color_set9"]) ? $options["dark_mode_btn_color_set9"]['color'] : '#C1D2BB',
273 'btn_bg' => isset($options["dark_mode_btn_color_set9"]) ? $options["dark_mode_btn_color_set9"]['background'] : '#095541',
274 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set9"]) ? $options["dark_mode_btn_color_set9"]['hover_color'] : '#C1D2BB',
275 'btn_hover_bg' => isset($options["dark_mode_btn_color_set9"]) ? $options["dark_mode_btn_color_set9"]['hover_background'] : '#073d2f',
276 ],
277 'set10' => [
278 'bg' => isset($options["dark_mode_color_set10"]) ? $options["dark_mode_color_set10"]['background'] : '#171004',
279 'secondary_bg' => isset($options["dark_mode_color_set10"]) ? $options["dark_mode_color_set10"]['secondary_background'] : '#211706',
280 'text_color' => isset($options["dark_mode_link_color_set10"]) ? $options["dark_mode_link_color_set10"]['text'] : '#E0D2BD',
281 'link_color' => isset($options["dark_mode_link_color_set10"]) ? $options["dark_mode_link_color_set10"]['color'] : '#e09525',
282 'link_hover_color' => isset($options["dark_mode_link_color_set10"]) ? $options["dark_mode_link_color_set10"]['hover'] : '#E0D2BD',
283 'input_bg' => isset($options["dark_mode_input_color_set10"]) ? $options["dark_mode_input_color_set10"]['background'] : '#372911',
284 'input_text_color' => isset($options["dark_mode_input_color_set10"]) ? $options["dark_mode_input_color_set10"]['color'] : '#E0D2BD',
285 'input_placeholder_color' => isset($options["dark_mode_input_color_set10"]) ? $options["dark_mode_input_color_set10"]['placeholder'] : '#E0D2BD',
286 'border_color' => isset($options["dark_mode_border_color_set10"]) ? $options["dark_mode_border_color_set10"] : '#5D4010',
287 'btn_text_color' => isset($options["dark_mode_btn_color_set10"]) ? $options["dark_mode_btn_color_set10"]['color'] : '#E0D2BD',
288 'btn_bg' => isset($options["dark_mode_btn_color_set10"]) ? $options["dark_mode_btn_color_set10"]['background'] : '#5D4010',
289 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set10"]) ? $options["dark_mode_btn_color_set10"]['hover_color'] : '#E0D2BD',
290 'btn_hover_bg' => isset($options["dark_mode_btn_color_set10"]) ? $options["dark_mode_btn_color_set10"]['hover_background'] : '#372911',
291 ],
292 'set11' => [
293 'bg' => isset($options["dark_mode_color_set11"]) ? $options["dark_mode_color_set11"]['background'] : '#19081b',
294 'secondary_bg' => isset($options["dark_mode_color_set11"]) ? $options["dark_mode_color_set11"]['secondary_background'] : '#210a24',
295 'text_color' => isset($options["dark_mode_link_color_set11"]) ? $options["dark_mode_link_color_set11"]['text'] : '#c09dc2',
296 'link_color' => isset($options["dark_mode_link_color_set11"]) ? $options["dark_mode_link_color_set11"]['color'] : '#c832d4',
297 'link_hover_color' => isset($options["dark_mode_link_color_set11"]) ? $options["dark_mode_link_color_set11"]['hover'] : '#c09dc2',
298 'input_bg' => isset($options["dark_mode_input_color_set11"]) ? $options["dark_mode_input_color_set11"]['background'] : '#2c082f',
299 'input_text_color' => isset($options["dark_mode_input_color_set11"]) ? $options["dark_mode_input_color_set11"]['color'] : '#c09dc2',
300 'input_placeholder_color' => isset($options["dark_mode_input_color_set11"]) ? $options["dark_mode_input_color_set11"]['placeholder'] : '#c09dc2',
301 'border_color' => isset($options["dark_mode_border_color_set11"]) ? $options["dark_mode_border_color_set11"] : '#440649',
302 'btn_text_color' => isset($options["dark_mode_btn_color_set11"]) ? $options["dark_mode_btn_color_set11"]['color'] : '#c09dc2',
303 'btn_bg' => isset($options["dark_mode_btn_color_set11"]) ? $options["dark_mode_btn_color_set11"]['background'] : '#440649',
304 'btn_text_hover_color' => isset($options["dark_mode_btn_color_set11"]) ? $options["dark_mode_btn_color_set11"]['hover_color'] : '#c09dc2',
305 'btn_hover_bg' => isset($options["dark_mode_btn_color_set11"]) ? $options["dark_mode_btn_color_set11"]['hover_background'] : '#2c082f',
306 ],
307 ];
308
309 $selected_set_key = isset($options['color_pallets']) ? $options['color_pallets'] : 'set1';
310 $selected_set = $dark_mode_color_palettes[$selected_set_key] ?? $dark_mode_color_palettes['set1'];
311
312 // Output as CSS variables
313 foreach ($selected_set as $key => $value) {
314 echo '--darkify_dark_mode_' . esc_attr($key) . ': ' . esc_attr($value) . ';';
315 }
316 ?>
317 }
318 </style>
319 <?php } else {
320 /*
321 * `dark` on <html> is the de-facto convention a React admin themes itself
322 * off — Tailwind's class strategy, shadcn/ui, and Darkify's own React admin
323 * (`@custom-variant dark (&:is(.dark *))`) all key on exactly this class.
324 *
325 * It used to be added only on Darkify's own SPA pages, which is why a
326 * React-based admin screen from ANOTHER plugin stayed stubbornly light while
327 * the rest of wp-admin went dark: such an app doesn't take its colours from
328 * the cascade at all, it reads design tokens that only switch when `dark` is
329 * present, and that class never arrived. Mirroring Admin Panel Dark Mode
330 * onto it here — on every admin screen, not just ours — lets any app
331 * following the convention inherit the theme with no plugin-specific
332 * handling on either side.
333 *
334 * Setting it in <head> means the very first paint is already dark; the
335 * runtime half of the mirror lives in client_main.js so the admin-bar switch
336 * re-themes those screens live too. The `h.classList.add('dark')` call is
337 * emitted as a static literal in the snippet below.
338 */
339 /*
340 * `d` gates this FOUC snippet on Admin Panel Dark Mode actually being ON.
341 * It used to be implicit: with the option off this template was never
342 * included on an admin screen. Darkify's own SPA screens now always
343 * include it (so the admin-bar icon can toggle without a reload), so
344 * without this check a stale `darkify_admin_panel_last_state = "1"` would
345 * darken the screen even though the option is off.
346 *
347 * Nested ifs, NOT `s==='1'&&d==='1'`: this whole template is printed
348 * through wp_kses() (see the bottom of the file), whose entity
349 * normalization rewrites a bare `&` to `&amp;` — script content is raw
350 * text, so `&&` would reach the browser as `&amp;&amp;` and kill the
351 * snippet with a SyntaxError. Keep this snippet free of `&` (and `<`).
352 */
353 /*
354 * Effective admin darkening for THIS screen. Block Editor Dark Mode is
355 * independent of Admin Panel Dark Mode: the block editor darkens when Block
356 * Editor Dark Mode is on even if Admin Panel Dark Mode is off. Reused for the
357 * runtime gate (darkify_admin_panel_dark_enabled) below.
358 */
359 $darkify_screen = \function_exists('get_current_screen') ? \get_current_screen() : null;
360 $darkify_is_block_editor = $darkify_screen && \method_exists($darkify_screen, 'is_block_editor') && $darkify_screen->is_block_editor();
361 $darkify_block_editor_dark = !empty($options['block_editor_dark_mode']);
362 $darkify_effective_admin_dark = (!empty($options['enable_admin_panel_dark_mode']) || ($darkify_is_block_editor && $darkify_block_editor_dark)) ? '1' : '0';
363 $darkify_admin_dark_on = $darkify_effective_admin_dark;
364 ?>
365 <script type="text/javascript" class="darkify_inline_js">(function(){var s=localStorage.darkify_admin_panel_last_state,t=localStorage.darkify_selected_theme||'set1',d='<?php echo esc_attr($darkify_admin_dark_on); ?>';if(s==='1'){if(d==='1'){var h=document.documentElement;h.classList.add('darkify_dark_mode_enabled');h.classList.add('darkify-'+t);h.classList.add('dark');}}}());</script>
366 <style type="text/css" class="darkify_inline_css">
367 :root {
368 --darkify_dark_mode_bg: #181a1b;
369 --darkify_dark_mode_secondary_bg: #202324;
370 --darkify_dark_mode_text_color: #c8c4bd;
371 --darkify_dark_mode_link_color: #6aafe2;
372 --darkify_dark_mode_link_hover_color: #4f94c3;
373 --darkify_dark_mode_input_bg: #2D2D2D;
374 --darkify_dark_mode_input_text_color: #BEBEBE;
375 --darkify_dark_mode_input_placeholder_color: #989898;
376 --darkify_dark_mode_border_color: #4A4A4A;
377 --darkify_dark_mode_btn_bg: #2D2D2D;
378 --darkify_dark_mode_btn_text_color: #BEBEBE;
379 --darkify_dark_mode_btn_hover_bg: #BEBEBE;
380 --darkify_dark_mode_btn_text_hover_color: #2D2D2D;
381 }
382 </style>
383 <?php }
384 if ($enable_scrollbar_dark) {
385 $dark_mode_scrollbar_track_bg = !empty($options["scrollbar_color"]) ? $options["scrollbar_color"]['dark_mode_scrollbar_track_bg'] : '';
386 $dark_mode_scrollbar_thumb_bg = !empty($options["scrollbar_color"]) ? $options["scrollbar_color"]['dark_mode_scrollbar_thumb_bg'] : '';
387 include DarkifyUtils::darkify_locate_template('views/scrollbar.php');
388 }
389 ?>
390
391 <script type="text/javascript" class="darkify_inline_js">
392 var darkify_switch_unique_id = "<?php echo esc_attr($this->unique_id); ?>";
393 var darkify_is_this_admin_panel = "<?php echo esc_attr(is_admin() ? "1" : "0"); ?>";
394 var darkify_enable_default_dark_mode = "<?php echo esc_attr($enable_default_dark_mode); ?>";
395 var darkify_enable_os_aware = "<?php echo esc_attr($enable_os_aware); ?>";
396 var darkify_enable_keyboard_shortcut = "<?php echo esc_attr($enable_keyboard_shortcut); ?>";
397 var darkify_keyboard_shortcut_keys = "<?php echo esc_attr($keyboard_shortcut_keys); ?>";
398 var darkify_enable_time_based_dark = "<?php echo esc_attr($enable_time_based_dark); ?>";
399 var darkify_time_based_dark_start = "<?php echo esc_attr($time_based_dark_start ? $time_based_dark_start : "19:00"); ?>";
400 var darkify_time_based_dark_stop = "<?php echo esc_attr($time_based_dark_stop ? $time_based_dark_stop : "07:00"); ?>";
401 var darkify_enable_switch_dragging = "<?php echo esc_attr($enable_switch_dragging); ?>";
402 var darkify_enable_switch_attention = "<?php echo esc_attr($enable_switch_attention); ?>";
403 var darkify_switch_attention_effect = "<?php echo esc_attr($switch_attention_effect); ?>";
404
405 var darkify_alternative_dark_mode_switch = "<?php echo esc_attr($alternative_dark_mode_switcher); ?>";
406 var darkify_enable_frontend_iframe_dark_mode = "<?php echo esc_attr($enable_frontend_iframe_dark_mode); ?>";
407 var darkify_enable_low_image_brightness = "<?php echo esc_attr($enable_low_image_brightness); ?>";
408 var darkify_image_brightness_to = "<?php echo esc_attr($low_image_brightness_label); ?>";
409 var darkify_disallowed_low_brightness_images = "<?php echo esc_attr($disallowed_low_brightness_images); ?>";
410 var darkify_enable_image_grayscale = "<?php echo esc_attr($enable_image_grayscale); ?>";
411 var darkify_image_grayscale_to = "<?php echo esc_attr($image_grayscale_label); ?>";
412 var darkify_disallowed_grayscale_images = "<?php echo esc_attr($disallowed_low_grayscale_images); ?>";
413 var darkify_enable_bg_image_darken = "<?php echo esc_attr($enable_low_image_darken); ?>";
414 var darkify_bg_image_darken_to = "<?php echo esc_attr($low_image_darken_label); ?>";
415 var darkify_enable_invert_inline_svg = "<?php echo esc_attr($enable_invert_inline_svg); ?>";
416 var darkify_enable_invert_images = "<?php echo esc_attr($enable_invert_images); ?>";
417 var darkify_invert_images_allowed_urls = "<?php echo esc_attr($invert_images_allowed_urls_arr); ?>";
418 var darkify_image_replacements = "<?php echo esc_attr($image_replacements) ?>";
419 var darkify_enable_low_video_brightness = "<?php echo esc_attr($enable_low_video_brightness); ?>";
420 var darkify_video_brightness_to = "<?php echo esc_attr($low_video_brightness_label); ?>";
421 var darkify_enable_video_grayscale = "<?php echo esc_attr($enable_video_grayscale); ?>";
422 var darkify_video_grayscale_to = "<?php echo esc_attr($video_grayscale_label); ?>";
423 var darkify_video_replacements = "<?PHP echo esc_attr($video_replacements); ?>";
424 var darkify_allowed_elements = "<?php echo esc_attr($this->utils->generateAllowedElementsStr($options)); ?>";
425 var darkify_allowed_elements_raw = "<?php echo esc_attr($allowed_elements); ?>";
426 var darkify_allowed_elements_force_to_correct = "<?php echo esc_attr($allowed_elements_force_to_correct); ?>";
427
428 var darkify_disallowed_elements = "<?php echo esc_attr($this->utils->generateDisallowedElementsStr($options, $this->external_support)); ?>";
429 var darkify_disallowed_elements_raw = "<?php echo esc_attr($disallowed_elements); ?>";
430 var darkify_disallowed_elements_force_to_correct = "<?php echo esc_attr($disallowed_elements_force_to_correct); ?>";
431
432 var darkify_allowed_btn_class = <?php echo json_encode($this->utils->addButtonClassByDarkify($options)); ?>;
433
434 var darkify_gradient_handling = "<?php echo esc_attr($darkify_gradient_handling); ?>";
435 var darkify_shadow_handling = "<?php echo esc_attr($darkify_shadow_handling); ?>";
436 var darkify_brand_color_handling = "<?php echo esc_attr($darkify_brand_color_handling); ?>";
437 var darkify_color_overrides = <?php echo wp_json_encode($darkify_color_overrides); ?>;
438 </script>
439 <?php
440 $output = ob_get_clean();
441 $tags_allowed_in_output = array(
442 'style' => array('type' => array(), 'class' => array()),
443 'script' => array('type' => array(), 'class' => array())
444 );
445 echo wp_kses($this->utils->minify_string($output), $tags_allowed_in_output);
446