PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.3.2
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.3.2
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
← All changes | src/Admin/Admin.php +149 -348 2.0.31.3.2 View file →
@@ -12,15 +12,13 @@
12 12 */
13 13
14 14 namespace ThemeAtelier\Darkify\Admin;
15 15
16 -use ThemeAtelier\Darkify\Admin\ReviewNotice\ReviewNotice;
17 -use ThemeAtelier\Darkify\Admin\ReviewNotice\ThemeAtelier_Offer_Banner;
18 -use ThemeAtelier\Darkify\Admin\Schema\SchemaDefaults;
16 +use ThemeAtelier\Darkify\Admin\TADiscountPage\TADiscountPage;
19 17 use ThemeAtelier\Darkify\Admin\Views\DarkifyOptions;
20 -use ThemeAtelier\Darkify\Includes\DarkifyExternalSupport;
21 -use ThemeAtelier\Darkify\Includes\DarkifyUtils;
22 -use ThemeAtelier\Darkify\Admin\DBUpdates;
18 +use ThemeAtelier\Darkify\Helpers\DarkifyExternalSupport;
19 +use ThemeAtelier\Darkify\Helpers\DarkifyUtils;
20 +use ThemeAtelier\Darkify\Helpers\Helpers;
23 21
24 22 /**
25 23 * The admin class
26 24 */
@@ -27,8 +25,17 @@
27 25 class Admin
28 26 {
29 27
30 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 + /**
31 38 * The min of this plugin.
32 39 *
33 40 * @since 1.0.0
34 41 * @access private
@@ -34,360 +41,155 @@
34 41 * @access private
35 42 * @var string $min The slug of this plugin.
36 43 */
37 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;
38 54 public $utils;
39 55 public $settings;
40 56 public $external_support;
57 +
58 + public $unique_id;
59 +
41 60 private $plugin_name;
42 - private $version;
43 - public $unique_id;
44 61
45 62 /**
46 63 * The class constructor.
47 64 *
48 - * @param string $plugin_name The slug of the plugin.
65 + * @param string $plugin_slug The slug of the plugin.
49 66 * @param string $version Current version of the plugin.
50 67 */
51 - public function __construct($plugin_name, $version)
68 + function __construct($plugin_slug, $version)
52 69 {
53 - $this->plugin_name = $plugin_name;
54 - $this->version = $version;
55 70 $this->utils = new DarkifyUtils($this);
56 71 $this->external_support = new DarkifyExternalSupport($this);
57 - $this->min = (apply_filters('darkify_dev_mode', false) || WP_DEBUG) ? '' : '.min';
58 72 if (function_exists('wp_rand')) {
59 73 $this->unique_id = wp_rand();
60 74 }
75 + DarkifyOptions::options('darkify');
61 76
62 - add_action('current_screen', function ($screen) {
63 - $options = get_option('darkify');
64 - $block_editor_dark_mode = isset($options['block_editor_dark_mode']) ? $options['block_editor_dark_mode'] : false;
65 - $enable_admin_panel_dark_mode = isset($options['enable_admin_panel_dark_mode']) ? $options['enable_admin_panel_dark_mode'] : false;
66 - $is_block_editor = method_exists($screen, 'is_block_editor') && $screen->is_block_editor();
77 + $options = get_option('darkify');
78 + $enable_admin_panel_dark_mode = isset($options['enable_admin_panel_dark_mode']) ? $options['enable_admin_panel_dark_mode'] : false;
79 + $this->plugin_name = $plugin_slug;
67 80
68 - // Block Editor Dark Mode is INDEPENDENT of Admin Panel Dark Mode:
69 - // the block editor darkens whenever Block Editor Dark Mode is on,
70 - // even if the rest of wp-admin stays light. Every other admin screen
71 - // still keys on Admin Panel Dark Mode.
72 - $needs_engine = $is_block_editor
73 - ? (bool) $block_editor_dark_mode
74 - : (bool) $enable_admin_panel_dark_mode;
81 + add_filter('plugin_action_links', array($this, 'add_plugin_action_links'), 10, 2);
75 82
76 - // Darkify's own settings/help screens additionally load it even while
77 - // the option is OFF, so flipping "Admin Panel Dark Mode" in the React
78 - // admin can show the admin-bar icon (and have it actually work)
79 - // immediately instead of only after a reload. Loading it here cannot
80 - // darken anything on its own: both the FOUC snippet in
81 - // header_script.php and darkify_check_preloading() in client_main.js
82 - // are gated on `darkify_admin_panel_dark_enabled`.
83 - if ($needs_engine || $this->is_darkify_spa_page()) {
84 - add_action('admin_bar_menu', array($this, 'darkify_admin_bar_switch'), 9999);
85 - add_action('admin_print_scripts', array($this, 'darkify_admin_header_script'), 1);
86 - add_action('admin_footer', array($this, 'darkify_admin_footer_script'));
87 - }
88 - });
83 + add_action('admin_enqueue_scripts', array($this, 'darkify_admin_enqueue'));
89 84
90 - new ReviewNotice();
91 - new DBUpdates();
92 - if (! defined('THEMEATELIER_OFFER_BANNER_LOADED')) {
93 - define('THEMEATELIER_OFFER_BANNER_LOADED', true);
94 - ThemeAtelier_Offer_Banner::instance();
85 + if ($enable_admin_panel_dark_mode) {
86 + add_action('admin_bar_menu', array($this, 'darkify_admin_bar_switch'), 9999);
87 + add_action('admin_print_scripts', array($this, 'darkify_admin_header_script'), 1);
88 + add_action('admin_footer', array($this, 'darkify_admin_footer_script'));
95 89 }
96 90
97 - // Building the schema is what evaluates every `__()` in
98 - // src/Admin/Views/*.php, so the text domain has to be registered first —
99 - // Darkify::load_textdomain() runs on this same hook at priority 1.
100 - add_action('after_setup_theme', array($this, 'init_components'));
101 - add_filter('autoptimize_filter_js_exclude', array($this, 'darkify_exclude_js_from_cache_plugins'));
102 - add_action('admin_init', [$this, 'load_classic_editor_scripts']);
103 - add_filter('admin_footer_text', array($this, 'darkify_admin_footer'), 1, 2);
104 - $active_plugins = get_option('active_plugins');
105 - foreach ($active_plugins as $active_plugin) {
106 - $_temp = strpos($active_plugin, 'darkify.php');
107 - if (false != $_temp) {
108 - add_filter('plugin_action_links_' . DARKIFY_BASENAME, array($this, 'add_plugin_action_links'), 10, 2);
109 - add_filter('plugin_row_meta', array($this, 'after_darkify_row_meta'), 10, 4);
110 - }
111 - }
91 + add_action('admin_menu', array($this, 'add_plugin_page'));
92 + new TADiscountPage();
112 93 }
113 94
114 - public function init_components()
115 - {
116 - DarkifyOptions::options('darkify');
117 - $this->seed_default_options();
118 - }
119 -
120 - /**
121 - * Write the schema's defaults into the `darkify` option on a fresh install.
122 - *
123 - * Nothing used to create that option until the first save in the admin. Up to
124 - * that point the two halves of the plugin disagreed: the React admin resolved
125 - * each field from the schema (so the Switch Toggler showed Orbit, the declared
126 - * default), while the frontend read the raw option — found nothing — and fell
127 - * back to the literal in its own template, rendering the Classic switcher. Same
128 - * class of mismatch for every other field whose template fallback differs from
129 - * its declared default.
130 - *
131 - * Seeding makes the stored values the single source both sides read, so a site
132 - * ships with exactly what the admin displays before anyone touches Settings.
133 - *
134 - * Runs on `init` (every request, admin and frontend), right after
135 - * the config classes have registered their sections, and is a no-op once the
136 - * option exists — so it never overwrites a user's saved settings, and an
137 - * upgrade from an older version is left alone.
138 - */
139 - private function seed_default_options()
140 - {
141 - $existing = get_option('darkify');
142 - if (is_array($existing) && ! empty($existing)) {
143 - return;
144 - }
145 -
146 - $defaults = SchemaDefaults::for_option('darkify');
147 - if (empty($defaults)) {
148 - return;
149 - }
150 -
151 - // `update_option` rather than `add_option`: an install that already holds
152 - // an empty/corrupt value (a stray '' or false) gets seeded too.
153 - update_option('darkify', $defaults);
154 - }
155 -
156 - /**
157 - * Whether the current screen is one of Darkify's own React SPA screens
158 - * (Settings / Get Help) — the only place the Admin Panel Dark Mode option can
159 - * be toggled, and therefore the only place that needs the engine loaded up
160 - * front so the admin-bar icon can react instantly.
161 - */
162 - public function is_darkify_spa_page(): bool
163 - {
164 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only screen check.
165 - $page = isset($_GET['page']) ? \sanitize_key(\wp_unslash($_GET['page'])) : '';
166 - return \in_array($page, Assets::SPA_SLUGS, true);
167 - }
168 -
169 - public function darkify_exclude_js_from_cache_plugins($excludes)
170 - {
171 - $excludes .= ',client_main.js,client_main.min.js';
172 - return $excludes;
173 - }
174 -
175 95 public function enqueue_styles()
176 96 {
177 - $options = get_option('darkify');
178 - $enable_admin_panel_dark_mode = isset($options["enable_admin_panel_dark_mode"]) ? $options["enable_admin_panel_dark_mode"] : false;
179 - // Block Editor Dark Mode darkens the editor independently of Admin Panel
180 - // Dark Mode, so the stylesheet must load there too.
181 - $block_editor_dark_mode = isset($options['block_editor_dark_mode']) ? $options['block_editor_dark_mode'] : false;
182 - $screen = \function_exists('get_current_screen') ? \get_current_screen() : null;
183 - $is_block_editor = $screen && \method_exists($screen, 'is_block_editor') && $screen->is_block_editor();
184 - $allow_admin_dark = $enable_admin_panel_dark_mode || ($is_block_editor && $block_editor_dark_mode);
185 - // Darkify's own screens always get the stylesheet so the admin-bar icon
186 - // can be revealed the moment the option is switched on. It only styles
187 - // `.darkify_*` classes, so it is inert until the engine adds them.
188 - if (($allow_admin_dark || $this->is_darkify_spa_page()) && $this->darkify_is_dark_mode_allowed()) {
189 - if (!wp_style_is('darkify-admin-switch', 'enqueued')) {
190 - wp_enqueue_style('darkify-admin-switch', DARKIFY_DIR_URL . 'src/assets/css/client_main' . $this->min . '.css', array(), $this->darkify_asset_version('src/assets/css/client_main' . $this->min . '.css'), 'all');
191 - }
192 - }
193 - // Review notice CSS
194 - wp_enqueue_style('darkify-review-notice', DARKIFY_DIR_URL . 'src/Admin/ReviewNotice/assets/css/review-notice' . $this->min . '.css', array(), DARKIFY_VERSION, 'all');
97 + wp_enqueue_style('ico-font', DARKIFY_DIR_URL . 'src/assets/css/icofont.css', array(), DARKIFY_VERSION, 'all');
98 + wp_enqueue_style('darkify-admin', DARKIFY_DIR_URL . 'src/Admin/assets/css/darkify-admin.css', array(), DARKIFY_VERSION, 'all');
195 99 }
196 100
197 101 public function enqueue_scripts($hook)
198 102 {
199 - $options = get_option('darkify');
200 - $enable_admin_panel_dark_mode = isset($options["enable_admin_panel_dark_mode"]) ? $options["enable_admin_panel_dark_mode"] : false;
201 - $is_spa = $this->is_darkify_spa_page();
202 - if (! $this->darkify_is_dark_mode_allowed()) {
103 + if ($hook !== 'toplevel_page_darkify') {
203 104 return;
204 105 }
205 -
206 - // Mirror the `current_screen` engine-load rule exactly, so the engine is
207 - // only enqueued where its inline config (header_script.php) is ALSO
208 - // printed. Block Editor Dark Mode is independent of Admin Panel Dark
209 - // Mode: the block editor loads the engine when Block Editor Dark Mode is
210 - // on (regardless of Admin Panel Dark Mode); every other admin screen
211 - // keys on Admin Panel Dark Mode. (A SPA screen always gets the config.)
212 - if (! $is_spa) {
213 - $screen = \function_exists('get_current_screen') ? \get_current_screen() : null;
214 - $is_block_editor = $screen && \method_exists($screen, 'is_block_editor') && $screen->is_block_editor();
215 - $block_editor_dark_mode = isset($options['block_editor_dark_mode']) ? $options['block_editor_dark_mode'] : false;
216 - $allow = $is_block_editor ? (bool) $block_editor_dark_mode : (bool) $enable_admin_panel_dark_mode;
217 - if (! $allow) {
218 - return;
219 - }
220 - }
221 -
222 - wp_enqueue_script(
223 - 'darkify-admin-client-main',
224 - DARKIFY_DIR_URL . 'src/assets/js/client_main' . $this->min . '.js',
225 - array(),
226 - $this->darkify_asset_version('src/assets/js/client_main' . $this->min . '.js')
227 - );
106 + wp_enqueue_script('darkify-admin', DARKIFY_DIR_URL . 'src/Admin/assets/js/darkify-admin.js', array(), DARKIFY_VERSION, 'all');
228 107 }
229 108
230 - /**
231 - * Cache-busting version for a bundled asset: the plugin version plus the
232 - * file's mtime, so rebuilding client_main.js/.css (which does NOT bump the
233 - * plugin version) still changes the URL and browsers fetch the new file
234 - * instead of serving a stale one. Mirrors Admin\Assets::asset_version().
235 - */
236 - public function darkify_asset_version(string $relative_path): string
109 + public function add_plugin_action_links($links, $file)
237 110 {
238 - $abs = DARKIFY_PATH . $relative_path;
239 - $mtime = \is_readable($abs) ? \filemtime($abs) : false;
240 - return $mtime ? DARKIFY_VERSION . '.' . $mtime : DARKIFY_VERSION;
241 - }
242 -
243 - /*
244 - Dequeue Darkify scripts and styles on specific admin pages (e.g., MainWP pages)
245 - */
246 -
247 - public function admin_dequeue_for_specefic_pages()
248 - {
249 - $page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';
250 - $dequeue_pages = array(
251 - 'mainwp_tab',
252 - 'managesites',
253 - 'ManageClients',
254 - 'CostSummary',
255 - 'InsightsOverview',
256 - 'Extensions',
257 - 'RESTAPI',
258 - 'mainwp-setup',
259 - 'ThemesManage',
260 - 'PluginsManage',
261 - 'InsightsManage',
262 - 'ManageGroups',
263 - 'UpdatesManage',
264 - 'PluginsInstall',
265 - 'PluginsAutoUpdate',
266 - 'PluginsIgnore',
267 - 'PluginsAbandoned',
268 - 'PluginsIgnoredAbandoned',
269 - 'ThemesInstall',
270 - 'ThemesAutoUpdate',
271 - 'ThemesIgnore',
272 - 'ThemesAbandoned',
273 - 'ThemesIgnoredAbandoned',
274 - 'UserBulkManage',
275 - 'UserBulkAdd',
276 - 'BulkImportUsers',
277 - 'UpdateAdminPasswords',
278 - 'PostBulkManage',
279 - 'Extensions-Mainwp-Backups',
280 - 'Extensions-Mainwp-Security',
281 - 'Extensions-Mainwp-Analytics',
282 - 'Mainwp-Monitoring',
283 - 'Extensions-Mainwp-Agency',
284 - 'Extensions-Mainwp-Administrative',
285 - 'Extensions-Mainwp-Development',
286 - 'Extensions-Mainwp-Performance',
287 - 'ClientAddNew',
288 - 'ClientImport',
289 - 'ManageCostTracker',
290 - 'CostTrackerAdd',
291 - 'AddApiKeys',
292 - );
293 -
294 -
295 - if (in_array($page, $dequeue_pages, true)) {
296 - wp_deregister_style('darkify-admin-switch');
297 - wp_dequeue_script('darkify-admin-client-main');
111 + if (DARKIFY_BASENAME === $file) {
112 + $new_links = array(
113 + sprintf('<a href="%s">%s</a>', admin_url('admin.php?page=darkify#tab=control'), __('Settings', 'darkify')),
114 + );
115 + return array_merge($new_links, $links);
298 116 }
117 + return $links;
299 118 }
300 119
301 - /**
302 - * Replace wp-admin's footer credit with Darkify's review request, on
303 - * Darkify's own screens only.
304 - *
305 - * Screens are matched by page slug (`is_darkify_spa_page()`) rather than by
306 - * a hardcoded screen id, so both the Settings and Get Help SPA screens match
307 - * and the check keeps working if the menu is ever retitled. The slug list is
308 - * the same source of truth the assets already load from.
309 - *
310 - * @param string $text Existing footer text.
311 - *
312 - * @return string
313 - */
314 - public function darkify_admin_footer($text)
120 + public function darkify_admin_enqueue($page)
315 121 {
316 - if (! $this->is_darkify_spa_page()) {
317 - return $text;
318 - }
122 + $options = get_option('darkify');
123 + $enable_default_dark_mode = $options['enable_default_dark_mode'];
124 + $enable_time = $options['enable_time'];
125 + $enable_time_based_dark = isset($enable_time['enable_time_based_dark']) ? $enable_time['enable_time_based_dark'] : "";
126 + $time_based_dark_start = isset($enable_time['time_based_dark_start']['from']) ? $enable_time['time_based_dark_start']['from'] : "";
127 + $time_based_dark_stop = isset($enable_time['time_based_dark_start']['to']) ? $enable_time['time_based_dark_start']['to'] : "";
128 + $grayscale = $options['brightness'];
129 + $enable_low_image_brightness = isset($grayscale['enable_low_image_brightness']) ? $grayscale['enable_low_image_brightness'] : "";
130 + $low_image_brightness_label = isset($grayscale['low_image_brightness_label']) ? $grayscale['low_image_brightness_label'] : "";
131 + $grayscale = isset($options['grayscale']);
132 + $enable_image_grayscale = isset($grayscale['enable_image_grayscale']) ? $grayscale['enable_image_grayscale'] : "";
133 + $image_grayscale_label = isset($grayscale['image_grayscale_label']) ? $grayscale['image_grayscale_label'] : "";
134 + $disallowed_low_grayscale_images = isset($grayscale['disallowed_low_grayscale_images']) ? $grayscale['disallowed_low_grayscale_images'] : "";
135 + $darken_background = isset($options['darken_background']);
136 + $enable_low_image_darken = isset($darken_background['enable_low_image_darken']) ? $darken_background['enable_low_image_darken'] : "";
137 + $low_image_darken_label = isset($darken_background['low_image_darken_label']) ? $darken_background['low_image_darken_label'] : "";
138 + $video_brightness = isset($options['video_brightness']);
139 + $enable_low_video_brightness = isset($video_brightness['enable_low_video_brightness']) ? $video_brightness['enable_low_video_brightness'] : "";
140 + $low_video_brightness_label = isset($video_brightness['low_video_brightness_label']) ? $video_brightness['low_video_brightness_label'] : "";
141 + $video_grayscale = isset($options['video_grayscale']);
142 + $enable_video_grayscale = isset($video_grayscale['enable_video_grayscale']) ? $video_grayscale['enable_video_grayscale'] : "";
319 143
320 - return sprintf(
321 - /* translators: 1: start strong tag, 2: close strong tag. 3: start link 4: close link */
322 - __('<i>Enjoying %1$sDarkify?%2$s Please rate us %3$sWordPress.org%4$s. Your positive feedback will help us grow more. Thank you! 😊</i>', 'darkify'),
323 - '<strong>',
324 - '</strong>',
325 - '<span class="greet-footer-text-star">★★★★★</span> <a href="https://wordpress.org/support/plugin/darkify/reviews/#new-post" target="_blank" rel="noopener noreferrer">',
326 - '</a>'
327 - );
328 - }
144 + if ($options["enable_admin_panel_dark_mode"]) {
145 + if ($this->darkify_is_dark_mode_allowed()) {
146 + if (!wp_style_is('darkify-admin-switch', 'enqueued')) {
147 + wp_enqueue_style('darkify-admin-switch', DARKIFY_DIR_URL . 'src/assets/css/client_main.css', array(), DARKIFY_VERSION, 'all');
148 + }
149 + wp_enqueue_script('darkify-admin-client-main', DARKIFY_DIR_URL . 'src/assets/js/client_main.js', array(), DARKIFY_VERSION);
329 150
330 - // Plugin settings in plugin list
331 - public function add_plugin_action_links(array $links)
332 - {
333 - $new_links = array(
334 - sprintf('<a href="' . esc_url(admin_url('admin.php?page=darkify')) . '">' . esc_html__('Settings', 'darkify') . '</a>'),
335 - sprintf('<a target="_blank" href="https://wordpress.org/support/plugin/darkify/">' . esc_html__('Support', 'darkify') . '</a>'),
336 - );
337 -
338 - $links[] = sprintf('<a style="font-weight: bold;color:#35b747" target="_blank" href="https://darkifywp.com/pricing/?utm_source=darkify_plugin&utm_medium=action_link&utm_campaign=regular">%s</a>', esc_html__('Go Pro!', 'darkify'));
339 -
340 - return array_merge($new_links, $links);
341 - }
342 -
343 - /**
344 - * Add plugin row meta link.
345 - *
346 - * @since 2.0
347 - *
348 - * @param array $plugin_meta .
349 - * @param string $file .
350 - *
351 - * @return array
352 - */
353 - public function after_darkify_row_meta($plugin_meta, $file)
354 - {
355 -
356 - if (DARKIFY_BASENAME === $file) {
357 - $plugin_meta[] = '<a href="' . DARKIFY_DEMO_URL . '" target="_blank">' . __('Live Demo', 'darkify') . '</a>';
151 + $darkify_data = array(
152 + 'darkify_switch_unique_id' => $this->unique_id,
153 + 'darkify_is_this_admin_panel' => is_admin() ? "1" : "0",
154 + 'darkify_enable_default_dark_mode' => $enable_default_dark_mode,
155 + 'darkify_enable_os_aware' => $options["enable_os_aware"],
156 + 'darkify_enable_keyboard_shortcut' => $options["enable_keyboard_shortcut"],
157 + 'darkify_enable_time_based_dark' => $enable_time_based_dark,
158 + 'darkify_time_based_dark_start' => $time_based_dark_start ? $time_based_dark_start : "19:00",
159 + 'darkify_time_based_dark_stop' => $time_based_dark_stop ? $time_based_dark_stop : "07:00",
160 + 'darkify_alternative_dark_mode_switch' => $options["alternative_dark_mode_switcher"],
161 + 'darkify_enable_low_image_brightness' => $enable_low_image_brightness,
162 + 'darkify_image_brightness_to' => $low_image_brightness_label,
163 + 'darkify_enable_image_grayscale' => $enable_image_grayscale,
164 + 'darkify_image_grayscale_to' => $image_grayscale_label,
165 + 'darkify_disallowed_grayscale_images' => $disallowed_low_grayscale_images,
166 + 'darkify_enable_bg_image_darken' => $enable_low_image_darken,
167 + 'darkify_bg_image_darken_to' => $low_image_darken_label,
168 + 'darkify_enable_invert_inline_svg' => $options["enable_invert_inline_svg"],
169 + 'darkify_enable_low_video_brightness' => $enable_low_video_brightness,
170 + 'darkify_video_brightness_to' => $low_video_brightness_label,
171 + 'darkify_enable_video_grayscale' => $enable_video_grayscale,
172 + // Add more variables as needed...
173 + );
174 + wp_localize_script('darkify-admin-client-main', 'darkify_data', $darkify_data);
175 + }
358 176 }
359 -
360 - return $plugin_meta;
361 177 }
362 178
363 179 public function darkify_admin_bar_switch($wp_admin_bar)
364 180 {
365 - if (! $this->darkify_is_dark_mode_allowed()) {
366 - return;
181 + if ($this->darkify_is_dark_mode_allowed()) {
182 + $args = array(
183 + 'parent' => 'top-secondary',
184 + 'id' => 'darkify_admin_bar_switch_container',
185 + 'meta' => array(
186 + 'class' => 'darkify_admin_bar_switch_container',
187 + 'onclick' => 'darkify_switch_trigger()',
188 + )
189 + );
190 + $wp_admin_bar->add_node($args);
367 191 }
368 -
369 - $options = get_option('darkify');
370 - $enable_admin_panel_dark_mode = isset($options['enable_admin_panel_dark_mode']) ? $options['enable_admin_panel_dark_mode'] : false;
371 -
372 - // Everywhere but Darkify's own screens the node is only registered when
373 - // the option is on, so it is always visible. On the SPA screens it is
374 - // registered regardless and starts hidden while the option is off — the
375 - // React admin then just flips this class (see WpAdminBarBridge), which is
376 - // what makes the icon appear/disappear without a reload.
377 - $classes = 'darkify_admin_bar_switch_container';
378 - if (! $enable_admin_panel_dark_mode) {
379 - $classes .= ' darkify_admin_bar_hidden';
380 - }
381 -
382 - $wp_admin_bar->add_node(array(
383 - 'parent' => 'top-secondary',
384 - 'id' => 'darkify_admin_bar_switch_container',
385 - 'meta' => array(
386 - 'class' => $classes,
387 - 'onclick' => 'darkify_switch_trigger()',
388 - ),
389 - ));
390 192 }
391 193
392 194 public function darkify_is_dark_mode_allowed()
393 195 {
@@ -392,14 +194,9 @@
392 194 public function darkify_is_dark_mode_allowed()
393 195 {
394 196
395 197 $options = get_option('darkify');
396 - $options = is_array($options) ? $options : array();
397 - // Guarded read: `disallowed_admin_pages` has no schema default, so the
398 - // React settings save doesn't persist it until the field is used. Reading
399 - // it unguarded would emit an "Undefined array key" warning on every
400 - // dark-mode hook (see the Pro plugin's Admin.php for the full story).
401 - $disallowed_admin_pages = isset($options['disallowed_admin_pages']) ? $options['disallowed_admin_pages'] : '';
198 + $disallowed_admin_pages = isset($options["disallowed_admin_pages"]) ? $options["disallowed_admin_pages"] : "";
402 199 /* Disable on Disallowed Admin Plugins */
403 200 if ($this->utils->isRestrictedByDisallowedAdminPages($disallowed_admin_pages)) {
404 201 return False;
405 202 }
@@ -408,9 +205,9 @@
408 205
409 206 public function darkify_admin_header_script()
410 207 {
411 208 if ($this->darkify_is_dark_mode_allowed()) {
412 - include_once DarkifyUtils::darkify_locate_template('header_script.php');
209 + include_once Helpers::darkify_locate_template('header_script.php');
413 210 }
414 211 }
415 212
416 213 public function darkify_admin_footer_script()
@@ -415,40 +212,44 @@
415 212
416 213 public function darkify_admin_footer_script()
417 214 {
418 215 if ($this->darkify_is_dark_mode_allowed()) {
419 - include_once DarkifyUtils::darkify_locate_template('footer_script.php');
216 + include_once Helpers::darkify_locate_template('footer_script.php');
420 217 }
421 218 }
422 219
423 - /**
424 - * Load classic editor scripts.
425 - *
426 - * @since 5.0.0
427 - */
428 - public function load_classic_editor_scripts()
220 + public function add_plugin_page()
429 221 {
430 - $options = get_option('darkify');
431 - $classic_editor_dark_mode = isset($options['classic_editor_dark_mode']) ? $options['classic_editor_dark_mode'] : '';
432 - if (! current_user_can('edit_posts') && ! current_user_can('edit_pages')) {
433 - return;
434 - }
435 - if (get_user_option('rich_editing') !== 'true') {
436 - return;
437 - }
438 -
439 - // Bail if admin_classic_editor is not enabled.
440 - if (! wp_validate_boolean($classic_editor_dark_mode)) {
441 - return;
442 - }
443 -
444 - add_filter('mce_external_plugins', function ($plugins) {
445 - $plugins['darkify_button'] = plugins_url('src/assets/js/admin-classic-editor.js', DARKIFY_FILE);
446 - return $plugins;
447 - });
448 -
449 - add_filter('mce_buttons', function ($buttons) {
450 - $buttons[] = 'darkify_button';
451 - return $buttons;
452 - });
222 + // This page will be under "Settings"
223 + add_menu_page(
224 + esc_html__('Darkify', 'darkify'),
225 + esc_html__('Darkify', 'darkify'),
226 + 'manage_options',
227 + 'darkify',
228 + 'darkify_settings',
229 + '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">
230 + <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" />
231 + <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" />
232 + <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" />
233 + <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" />
234 + <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" />
235 + <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" />
236 + <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" />
237 + <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" />
238 + <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" />
239 +</svg>'),
240 + 9
241 + );
242 + do_action('darkify_before_upgrade_pro_menu');
243 + add_submenu_page(
244 + 'darkify',
245 + __(
246 + '👑 Upgrade to Pro!',
247 + 'darkify'
248 + ),
249 + sprintf('<span style="color: #35b747;font-weight: bold;" class="darkify-get-pro-text">%s</span>', __('👑 Upgrade to Pro!', 'darkify')),
250 + 'manage_options',
251 + 'https://themeatelier.net/downloads/darkify/'
252 + );
253 + do_action('darkify_after_upgrade_pro_menu');
453 254 }
454 255 }