PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.5.0
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.5.0
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 / footer_script.php

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

96 lines 4.8 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 $options = get_option('darkify');
11 $enable_dark_mode_switch = isset($options["enable_dark_mode_switch"]) ? $options["enable_dark_mode_switch"] : true;
12 $hide_on_desktop = isset($options["hide_on_desktop"]) ? $options["hide_on_desktop"] : '';
13 $hide_on_mobile = isset($options["hide_on_mobile"]) ? $options["hide_on_mobile"] : '';
14 $enable_admin_panel_dark_mode = isset($options["enable_admin_panel_dark_mode"]) ? $options["enable_admin_panel_dark_mode"] : '';
15 $block_editor_dark_mode = isset($options['block_editor_dark_mode']) ? $options['block_editor_dark_mode'] : false;
16 $hide_dark_mode_on_mobile = isset($hide_on_mobile["hide_dark_mode_on_mobile"]) ? $hide_on_mobile["hide_dark_mode_on_mobile"] : 0;
17 $type_of_hide_by = isset($hide_on_mobile["type_of_hide_by"]) ? $hide_on_mobile["type_of_hide_by"] : 0;
18
19 $normal_custom_css = isset($options["normal_custom_css"]) ? $options["normal_custom_css"] : "";
20 $custom_css = isset($options["custom_css"]) ? $options["custom_css"] : "";
21 $admin_custom_css = isset($options['admin_custom_css']) ? $options['admin_custom_css'] : "";
22
23 if (!is_admin()) {
24 if ($enable_dark_mode_switch) {
25 if (!$this->utils->is_hidden_by_user_agent($hide_on_desktop, $hide_dark_mode_on_mobile, $type_of_hide_by)) {
26 include_once DarkifyUtils::darkify_locate_template('views/switch.php');
27 }
28 }
29 }
30 ?>
31
32 <style type="text/css" class="darkify_inline_css">
33 <?php echo wp_strip_all_tags(DarkifyUtils::parseAndProcessNormalCustomCSS($normal_custom_css)); ?>
34 </style>
35 <style type="text/css" class="darkify_inline_css">
36 <?php echo wp_strip_all_tags(DarkifyUtils::parseAndProcessCustomCSS($custom_css, false)); ?>
37 </style>
38
39 <?php if (!is_admin()) { ?>
40 <script type="text/javascript" class="darkify_inline_js">
41 document.addEventListener("DOMContentLoaded", function(event) {
42 darkify_init_alternative_dark_mode_switch();
43 });
44 </script>
45 <?php }
46
47 if (is_admin() && $block_editor_dark_mode) {
48 ?><style type="text/css" class="darkify_inline_css">
49 <?php echo esc_html(DarkifyUtils::parseAndProcessCustomCSS($admin_custom_css, 'yes')); ?>
50 </style>
51 <?php
52 /* Check if block editor is on, then add the dark mode button there */
53 if ($enable_admin_panel_dark_mode) {
54 if (class_exists('WP_Block_Type_Registry')) {
55
56 if (get_current_screen() && 'post' === get_current_screen()->base && ('post' === get_current_screen()->post_type || 'page' === get_current_screen()->post_type)) { ?>
57 <script type="text/javascript" class="darkify_inline_js">
58 (function checkForWP() {
59 if (typeof wp === 'undefined' || typeof wp.domReady === 'undefined') {
60 // Wait and try again (e.g., if Gutenberg scripts haven’t loaded yet)
61 return setTimeout(checkForWP, 200);
62 }
63
64 wp.domReady(function() {
65 const observer = new MutationObserver(function(mutations) {
66 mutations.forEach(function(mutation) {
67 if (mutation.addedNodes && mutation.addedNodes.length) {
68 for (let i = 0; i < mutation.addedNodes.length; i++) {
69 const node = mutation.addedNodes[i];
70 if (node.classList && (node.classList.contains('edit-post-header-toolbar') || node.classList.contains('interface-pinned-items'))) {
71 const button = document.createElement('button');
72 button.className = 'darkify_block_editor_switch darkify_ignore';
73 button.innerHTML = '<div class="icon"></div>';
74 button.onclick = function() {
75 darkify_switch_trigger();
76 };
77 node.appendChild(button);
78 observer.disconnect();
79 return;
80 }
81 }
82 }
83 });
84 });
85 observer.observe(document.body, {
86 childList: true,
87 subtree: true
88 });
89 });
90 })();
91 </script>
92 <?php }
93 }
94 }
95 }
96