PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.4.7
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.4.7
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 1.3.1 All 56 releases
darkify / src / Admin / Admin.php

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

207 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-facing functionality of the plugin.
5 *
6 * @link https://themeatelier.net
7 * @since 1.0.0
8 *
9 * @package darkify
10 * @subpackage darkify/Admin
11 * @author ThemeAtelier<themeatelierbd@gmail.com>
12 */
13
14 namespace ThemeAtelier\Darkify\Admin;
15
16 use ThemeAtelier\Darkify\Admin\ReviewNotice\ReviewNotice;
17 use ThemeAtelier\Darkify\Admin\Views\DarkifyOptions;
18 use ThemeAtelier\Darkify\Helpers\DarkifyExternalSupport;
19 use ThemeAtelier\Darkify\Helpers\DarkifyUtils;
20 use ThemeAtelier\Darkify\Admin\DBUpdates;
21
22 /**
23 * The admin class
24 */
25 class Admin
26 {
27
28 /**
29 * The slug of this plugin.
30 *
31 * @since 1.0.0
32 * @access private
33 * @var string $plugin_slug The slug of this plugin.
34 */
35 private $plugin_slug;
36
37 /**
38 * The min of this plugin.
39 *
40 * @since 1.0.0
41 * @access private
42 * @var string $min The slug of this plugin.
43 */
44 private $min;
45
46 /**
47 * The version of this plugin.
48 *
49 * @since 1.0.0
50 * @access private
51 * @var string $version The current version of this plugin.
52 */
53 private $version;
54 public $utils;
55 public $settings;
56 public $external_support;
57 public $unique_id;
58 private $plugin_name;
59
60
61 /**
62 * The class constructor.
63 *
64 * @param string $plugin_slug The slug of the plugin.
65 * @param string $version Current version of the plugin.
66 */
67 function __construct($plugin_slug, $version)
68 {
69 $this->utils = new DarkifyUtils($this);
70 $this->external_support = new DarkifyExternalSupport($this);
71 if (function_exists('wp_rand')) {
72 $this->unique_id = wp_rand();
73 }
74
75 $options = get_option('darkify');
76
77 $enable_admin_panel_dark_mode = isset($options['enable_admin_panel_dark_mode']) ? $options['enable_admin_panel_dark_mode'] : false;
78 $this->plugin_name = $plugin_slug;
79 $this->min = (apply_filters('darkify_dev_mode', false) || WP_DEBUG) ? '' : '.min';
80 add_filter('plugin_action_links_' . DARKIFY_BASENAME, array($this, 'add_plugin_action_links'), 10, 2);
81 if ($enable_admin_panel_dark_mode) {
82 add_action('admin_bar_menu', array($this, 'darkify_admin_bar_switch'), 9999);
83 add_action('admin_print_scripts', array($this, 'darkify_admin_header_script'), 1);
84 add_action('admin_footer', array($this, 'darkify_admin_footer_script'));
85 }
86 add_action('admin_menu', array($this, 'add_plugin_page'));
87 new ReviewNotice();
88 new DBUpdates();
89 add_action('after_setup_theme', array($this, 'init_components'));
90 add_filter('autoptimize_filter_js_exclude', array($this, 'darkify_exclude_js_from_cache_plugins'));
91 }
92
93 public function init_components() {
94 DarkifyOptions::options('darkify');
95 }
96
97 public function darkify_exclude_js_from_cache_plugins($excludes)
98 {
99 $excludes .= ',client_main.js,client_main.min.js';
100 return $excludes;
101 }
102
103 public function enqueue_styles($hook)
104 {
105 if($hook === 'toplevel_page_darkify') {
106 wp_enqueue_style('darkify-help-page', DARKIFY_DIR_URL . 'src/Admin/HelpPage/assets/css/help-page' . $this->min . '.css', array(), DARKIFY_VERSION, 'all');
107 }
108
109 $options = get_option('darkify');
110 $enable_admin_panel_dark_mode = isset($options["enable_admin_panel_dark_mode"]) ? $options["enable_admin_panel_dark_mode"] : false;
111 if ($enable_admin_panel_dark_mode) {
112 if (!wp_style_is('darkify-admin-switch', 'enqueued')) {
113 wp_enqueue_style('darkify-admin-switch', DARKIFY_DIR_URL . 'src/assets/css/client_main' . $this->min . '.css', array(), DARKIFY_VERSION, 'all');
114 }
115 }
116 // Review notice CSS
117 wp_enqueue_style('darkify-review-notice', DARKIFY_DIR_URL . 'src/Admin/ReviewNotice/assets/css/review-notice' . $this->min . '.css', array(), DARKIFY_VERSION, 'all');
118 }
119
120 public function enqueue_scripts($hook)
121 {
122 $options = get_option('darkify');
123 $enable_admin_panel_dark_mode = isset($options["enable_admin_panel_dark_mode"]) ? $options["enable_admin_panel_dark_mode"] : false;
124 if ($enable_admin_panel_dark_mode) {
125 wp_enqueue_script('darkify-admin-client-main', DARKIFY_DIR_URL . 'src/assets/js/client_main' . $this->min . '.js', array(), DARKIFY_VERSION);
126 }
127
128 if($hook === 'toplevel_page_darkify') {
129 wp_enqueue_script('darkify-help-page', DARKIFY_DIR_URL . 'src/Admin/HelpPage/assets/js/help-page' . $this->min . '.js', array('darkify-plugins'), DARKIFY_VERSION, true);
130 }
131 }
132
133 // Plugin settings in plugin list
134 public function add_plugin_action_links(array $links)
135 {
136 $new_links = array(
137 sprintf('<a href="' . esc_url(admin_url('admin.php?page=darkify')) . '">' . esc_html__('Settings', 'darkify') . '</a>'),
138 sprintf('<a target="_blank" href="https://themeatelier.net/contact">' . esc_html__('Support', 'darkify') . '</a>'),
139 sprintf('<a style="font-weight: bold;color:#171717" target="_blank" href="https://darkifywp.com/pricing/?ref=1">' . esc_html__('Go Pro', 'darkify') . '</a>'),
140 );
141 return array_merge($new_links, $links);
142 }
143
144
145 public function darkify_admin_bar_switch($wp_admin_bar)
146 {
147 $args = array(
148 'parent' => 'top-secondary',
149 'id' => 'darkify_admin_bar_switch_container',
150 'meta' => array(
151 'class' => 'darkify_admin_bar_switch_container',
152 'onclick' => 'darkify_switch_trigger()',
153 )
154 );
155 $wp_admin_bar->add_node($args);
156 }
157
158 public function darkify_admin_header_script()
159 {
160 include_once DarkifyUtils::darkify_locate_template('header_script.php');
161 }
162
163 public function darkify_admin_footer_script()
164 {
165 include_once DarkifyUtils::darkify_locate_template('footer_script.php');
166 }
167
168 public function add_plugin_page()
169 {
170 // This page will be under "Settings"
171 add_menu_page(
172 esc_html__('Darkify', 'darkify'),
173 esc_html__('Darkify', 'darkify'),
174 'manage_options',
175 'darkify',
176 [$this, 'darkify_settings'],
177 'data:image/svg+xml;base64,' . base64_encode('<svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg">
178 <path d="M23.5 1.5C23.5 0.671573 22.8284 0 22 0C21.1716 0 20.5 0.671573 20.5 1.5V4.5C20.5 5.32843 21.1716 6 22 6C22.8284 6 23.5 5.32843 23.5 4.5V1.5Z" fill="white" />
179 <path d="M34 22C34 28.6274 28.6274 34 22 34C15.3726 34 10 28.6274 10 22C10 15.3726 15.3726 10 22 10C28.6274 10 34 15.3726 34 22Z" fill="white" />
180 <path d="M22 38C22.8284 38 23.5 38.6716 23.5 39.5V42.5C23.5 43.3284 22.8284 44 22 44C21.1716 44 20.5 43.3284 20.5 42.5V39.5C20.5 38.6716 21.1716 38 22 38Z" fill="white" />
181 <path d="M10.6863 10.6863C10.1005 11.2721 9.15074 11.2721 8.56495 10.6863L6.44363 8.56498C5.85784 7.97919 5.85784 7.02945 6.44363 6.44366C7.02942 5.85787 7.97916 5.85787 8.56495 6.44366L10.6863 8.56498C11.2721 9.15077 11.2721 10.1005 10.6863 10.6863Z" fill="white" />
182 <path d="M35.435 37.5564C36.0208 38.1421 36.9705 38.1421 37.5563 37.5564C38.1421 36.9706 38.1421 36.0208 37.5563 35.435L35.435 33.3137C34.8492 32.7279 33.8995 32.7279 33.3137 33.3137C32.7279 33.8995 32.7279 34.8493 33.3137 35.435L35.435 37.5564Z" fill="white" />
183 <path d="M10.6863 33.3137C11.2721 33.8995 11.2721 34.8492 10.6863 35.435L8.56495 37.5563C7.97916 38.1421 7.02942 38.1421 6.44363 37.5563C5.85784 36.9706 5.85784 36.0208 6.44363 35.435L8.56495 33.3137C9.15074 32.7279 10.1005 32.7279 10.6863 33.3137Z" fill="white" />
184 <path d="M37.5563 8.56496C38.1421 7.97918 38.1421 7.02943 37.5563 6.44364C36.9705 5.85786 36.0208 5.85786 35.435 6.44364L33.3137 8.56496C32.7279 9.15075 32.7279 10.1005 33.3137 10.6863C33.8995 11.2721 34.8492 11.2721 35.435 10.6863L37.5563 8.56496Z" fill="white" />
185 <path d="M6 22C6 22.8284 5.32843 23.5 4.5 23.5H1.5C0.671573 23.5 0 22.8284 0 22C0 21.1716 0.671573 20.5 1.5 20.5H4.5C5.32843 20.5 6 21.1716 6 22Z" fill="white" />
186 <path d="M42.5 23.5C43.3284 23.5 44 22.8284 44 22C44 21.1716 43.3284 20.5 42.5 20.5H39.5C38.6716 20.5 38 21.1716 38 22C38 22.8284 38.6716 23.5 39.5 23.5H42.5Z" fill="white" />
187 </svg>'),
188 9
189 );
190 do_action('darkify_before_upgrade_pro_menu');
191 add_submenu_page(
192 'darkify',
193 __(
194 '👑 Upgrade to Pro!',
195 'darkify'
196 ),
197 sprintf('<span style="color: #35b747;font-weight: bold;" class="darkify-get-pro-text">%s</span>', __('👑 Upgrade to Pro (70% Off)', 'darkify')),
198 'manage_options',
199 'https://darkifywp.com/pricing/?ref=1'
200 );
201 do_action('darkify_after_upgrade_pro_menu');
202 }
203
204 public function darkify_settings() {}
205
206 }
207