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

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

195 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ThemeAtelier\Darkify\Frontend;
4
5 use ThemeAtelier\Darkify\Includes\DarkifyExternalSupport;
6 use ThemeAtelier\Darkify\Includes\DarkifyUtils;
7
8 if (!defined('ABSPATH')) {
9 die;
10 } // Cannot access directly.
11
12 /**
13 * The public-facing functionality of the plugin.
14 *
15 * @link https://themeatelier.net
16 * @since 1.0.0
17 *
18 * @package Darkify
19 * @subpackage Darkify/public
20 */
21
22 /**
23 * The public-facing functionality of the plugin.
24 *
25 * Defines the plugin name, version, and two examples hooks for how to
26 * enqueue the public-facing stylesheet and JavaScript.
27 *
28 * @package Darkify
29 * @subpackage Darkify/public
30 * @author ThemeAtelier <themeatelierbd@gmail.com>
31 */
32 class Frontend
33 {
34
35 /**
36 * The ID of this plugin.
37 *
38 * @since 1.0.0
39 * @access private
40 * @var string $plugin_name The ID of this plugin.
41 */
42 private $plugin_name;
43
44 /**
45 * The version of this plugin.
46 *
47 * @since 1.0.0
48 * @access private
49 * @var string $version The current version of this plugin.
50 */
51 private $version;
52
53 public $utils;
54 public $settings;
55 public $external_support;
56 public $unique_id;
57
58 /**
59 * Initialize the class and set its properties.
60 *
61 * @since 1.0.0
62 * @param string $plugin_name The name of the plugin.
63 * @param string $version The version of this plugin.
64 */
65 public function __construct($plugin_name, $version)
66 {
67 $this->plugin_name = $plugin_name;
68 $this->version = $version;
69
70 $this->utils = new DarkifyUtils($this);
71 $this->external_support = new DarkifyExternalSupport($this);
72
73 new DarkifyShortcode($this);
74
75 if (function_exists('wp_rand')) {
76 $this->unique_id = wp_rand();
77 }
78
79 $options = get_option('darkify');
80 $show_in_menu = isset($options['show_in_menu']) ? $options['show_in_menu'] : "";
81 $enable_switcher_in_menu = isset($show_in_menu["enable_switch_in_menu"]) ? $show_in_menu["enable_switch_in_menu"] : false;
82
83 if ($enable_switcher_in_menu) {
84 add_filter('wp_nav_menu_items', array($this, 'darkify_switch_in_menu'), 10, 2);
85 }
86
87 add_action('wp_enqueue_scripts', array($this, 'darkify_client_enqueue'), 100);
88 add_action('login_enqueue_scripts', array($this, 'darkify_client_enqueue'));
89 add_action('register_enqueue_scripts', array($this, 'darkify_client_enqueue'));
90 add_action('wp_head', array($this, 'darkify_client_header_script'), 1);
91 add_action('login_head', array($this, 'darkify_client_header_script'), 1);
92 add_action('register_head', array($this, 'darkify_client_header_script'), 1);
93 add_action('wp_footer', array($this, 'darkify_client_footer_script'));
94 add_action('login_footer', array($this, 'darkify_client_footer_script'));
95 add_action('register_footer', array($this, 'darkify_client_footer_script'));
96
97 add_filter('autoptimize_filter_js_exclude', array($this, 'darkify_exclude_js_from_cache_plugins'));
98 }
99
100
101 public function darkify_exclude_js_from_cache_plugins($excludes)
102 {
103 $excludes .= ',client_main.js,client_main.min.js';
104 return $excludes;
105 }
106
107
108 function darkify_client_enqueue()
109 {
110 if ($this->darkify_is_dark_mode_allowed()) {
111
112 $options = get_option('darkify');
113 $enable_dark_switcher = isset($options['enable_dark_switcher']) ? $options['enable_dark_switcher'] : 'classic';
114 $min = (apply_filters('darkify_dev_mode', false) || WP_DEBUG) ? '' : '.min';
115 wp_enqueue_style('darkify-client-main', DARKIFY_DIR_URL . 'src/assets/css/client_main' . $min . '.css', array(), DARKIFY_VERSION);
116
117 // wp_enqueue_style("theme-{$enable_dark_switcher}", DARKIFY_DIR_URL . 'src/assets/css/switcher/' . $enable_dark_switcher . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all');
118
119 wp_register_style('theme-around', DARKIFY_DIR_URL . 'src/assets/css/switcher/around' . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all');
120 wp_register_style('theme-classic', DARKIFY_DIR_URL . 'src/assets/css/switcher/classic' . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all');
121 wp_register_style('theme-dark-inner', DARKIFY_DIR_URL . 'src/assets/css/switcher/dark-inner' . $min . '.css', array(), DARKIFY_VERSION, 'all');
122 wp_register_style('theme-dark-side', DARKIFY_DIR_URL . 'src/assets/css/switcher/dark-side' . $min . '.css', array(), DARKIFY_VERSION, 'all');
123 wp_register_style('theme-eclipse', DARKIFY_DIR_URL . 'src/assets/css/switcher/eclipse' . $min . '.css', array(), DARKIFY_VERSION, 'all');
124 wp_register_style('theme-expand', DARKIFY_DIR_URL . 'src/assets/css/switcher/expand' . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all');
125 wp_register_style('theme-half-sun', DARKIFY_DIR_URL . 'src/assets/css/switcher/half-sun' . $min . '.css', array(), DARKIFY_VERSION, 'all');
126 wp_register_style('theme-horizon', DARKIFY_DIR_URL . 'src/assets/css/switcher/horizon' . $min . '.css', array(), DARKIFY_VERSION, 'all');
127 wp_register_style('theme-inner-moon', DARKIFY_DIR_URL . 'src/assets/css/switcher/inner-moon' . $min . '.css', array(), DARKIFY_VERSION, 'all');
128 wp_register_style('theme-lightbulb', DARKIFY_DIR_URL . 'src/assets/css/switcher/lightbulb' . $min . '.css', array(), DARKIFY_VERSION, 'all');
129 wp_register_style('theme-simple', DARKIFY_DIR_URL . 'src/assets/css/switcher/simple' . $min . '.css', array(), DARKIFY_VERSION, 'all');
130 wp_register_style('theme-orbit', DARKIFY_DIR_URL . 'src/assets/css/switcher/orbit' . $min . '.css', array(), DARKIFY_VERSION, 'all');
131 wp_register_style('theme-duality', DARKIFY_DIR_URL . 'src/assets/css/switcher/duality' . $min . '.css', array(), DARKIFY_VERSION, 'all');
132 wp_register_style('theme-dual', DARKIFY_DIR_URL . 'src/assets/css/switcher/dual' . $min . '.css', array(), DARKIFY_VERSION, 'all');
133 wp_register_style('theme-shift', DARKIFY_DIR_URL . 'src/assets/css/switcher/shift' . $min . '.css', array(), DARKIFY_VERSION, 'all');
134 wp_register_style('theme-within', DARKIFY_DIR_URL . 'src/assets/css/switcher/within' . $min . '.css', array(), DARKIFY_VERSION, 'all');
135
136 wp_enqueue_script('darkify-client-main', DARKIFY_DIR_URL . 'src/assets/js/client_main' . $min . '.js', array('jquery'), DARKIFY_VERSION);
137 }
138 }
139 public function darkify_is_dark_mode_allowed()
140 {
141 $options = get_option('darkify');
142 /* Disable if Oxygen Builder is Opened */
143 if (isset($_GET['ct_builder'])) {
144 if ($_GET['ct_builder'] == "true") {
145 if (!isset($_GET['oxygen_iframe'])) {
146 return False;
147 }
148 }
149 }
150
151 return True;
152 }
153
154
155 public function darkify_client_header_script()
156 {
157 if ($this->darkify_is_dark_mode_allowed()) {
158 include_once DarkifyUtils::darkify_locate_template('header_script.php');
159 }
160 }
161
162 public function darkify_client_footer_script()
163 {
164 if ($this->darkify_is_dark_mode_allowed()) {
165 include_once DarkifyUtils::darkify_locate_template('footer_script.php');
166 }
167 }
168
169 function darkify_switch_in_menu($items, $args)
170 {
171 $options = get_option('darkify');
172 $show_in_menu = $options['show_in_menu'];
173 $select_menus = isset($show_in_menu['select_menus']) ? $show_in_menu['select_menus'] : [];
174
175 $last_shortcode = '';
176
177 if ($this->darkify_is_dark_mode_allowed() && isset($args->menu->term_id)) {
178 foreach ($select_menus as $select_menu) {
179
180 $switch_in_menu_location = $select_menu['switch_in_menu_location'] ?? '';
181 $darkify_menu_shortcode_helper = $select_menu['darkify_menu_shortcode_helper'] ?? '';
182 $menu_position = isset($select_menu['select_menu_position']) ? $select_menu['select_menu_position'] : 'after';
183 if ($args->menu->term_id == $switch_in_menu_location) {
184 $last_shortcode = $darkify_menu_shortcode_helper;
185 }
186 }
187 if ($last_shortcode) {
188 $items = ($menu_position == 'before') ? '<li class="menu-item">' . do_shortcode($last_shortcode) . '</li>' . $items : $items . '<li class="menu-item">' . do_shortcode($last_shortcode) . '</li>';
189 }
190 }
191
192 return $items;
193 }
194 }
195