PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.4.4
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.4.4
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.4, at src/Frontend/Frontend.php

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