| @@ -13,12 +13,11 @@ | ||
| 13 | 13 | |
| 14 | 14 | namespace ThemeAtelier\Darkify\Admin; |
| 15 | 15 | |
| 16 | 16 | use ThemeAtelier\Darkify\Admin\ReviewNotice\ReviewNotice; |
| 17 | -use ThemeAtelier\Darkify\Admin\ReviewNotice\ThemeAtelier_Offer_Banner; | |
| 18 | 17 | use ThemeAtelier\Darkify\Admin\Views\DarkifyOptions; |
| 19 | -use ThemeAtelier\Darkify\Includes\DarkifyExternalSupport; | |
| 20 | -use ThemeAtelier\Darkify\Includes\DarkifyUtils; | |
| 18 | +use ThemeAtelier\Darkify\Helpers\DarkifyExternalSupport; | |
| 19 | +use ThemeAtelier\Darkify\Helpers\DarkifyUtils; | |
| 21 | 20 | use ThemeAtelier\Darkify\Admin\DBUpdates; |
| 22 | 21 | |
| 23 | 22 | /** |
| 24 | 23 | * The admin class |
| @@ -26,8 +25,17 @@ | ||
| 26 | 25 | class Admin |
| 27 | 26 | { |
| 28 | 27 | |
| 29 | 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 | + /** | |
| 30 | 38 | * The min of this plugin. |
| 31 | 39 | * |
| 32 | 40 | * @since 1.0.0 |
| 33 | 41 | * @access private |
| @@ -33,99 +41,60 @@ | ||
| 33 | 41 | * @access private |
| 34 | 42 | * @var string $min The slug of this plugin. |
| 35 | 43 | */ |
| 36 | 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; | |
| 37 | 54 | public $utils; |
| 38 | 55 | public $settings; |
| 39 | 56 | public $external_support; |
| 57 | + public $unique_id; | |
| 40 | 58 | private $plugin_name; |
| 41 | - private $version; | |
| 42 | - public $unique_id; | |
| 43 | 59 | |
| 60 | + | |
| 44 | 61 | /** |
| 45 | 62 | * The class constructor. |
| 46 | 63 | * |
| 47 | - * @param string $plugin_name The slug of the plugin. | |
| 64 | + * @param string $plugin_slug The slug of the plugin. | |
| 48 | 65 | * @param string $version Current version of the plugin. |
| 49 | 66 | */ |
| 50 | - public function __construct($plugin_name, $version) | |
| 67 | + function __construct($plugin_slug, $version) | |
| 51 | 68 | { |
| 52 | - $this->plugin_name = $plugin_name; | |
| 53 | - $this->version = $version; | |
| 54 | 69 | $this->utils = new DarkifyUtils($this); |
| 55 | 70 | $this->external_support = new DarkifyExternalSupport($this); |
| 56 | - $this->min = (apply_filters('darkify_dev_mode', false) || WP_DEBUG) ? '' : '.min'; | |
| 57 | 71 | if (function_exists('wp_rand')) { |
| 58 | 72 | $this->unique_id = wp_rand(); |
| 59 | 73 | } |
| 60 | 74 | |
| 61 | - add_action('current_screen', function ($screen) { | |
| 62 | - $options = get_option('darkify'); | |
| 63 | - $block_editor_dark_mode = isset($options['block_editor_dark_mode']) ? $options['block_editor_dark_mode'] : false; | |
| 64 | - $enable_admin_panel_dark_mode = isset($options['enable_admin_panel_dark_mode']) ? $options['enable_admin_panel_dark_mode'] : false; | |
| 65 | - $is_block_editor = method_exists($screen, 'is_block_editor') && $screen->is_block_editor(); | |
| 75 | + $options = get_option('darkify'); | |
| 66 | 76 | |
| 67 | - // Block Editor Dark Mode is INDEPENDENT of Admin Panel Dark Mode: | |
| 68 | - // the block editor darkens whenever Block Editor Dark Mode is on, | |
| 69 | - // even if the rest of wp-admin stays light. Every other admin screen | |
| 70 | - // still keys on Admin Panel Dark Mode. | |
| 71 | - $needs_engine = $is_block_editor | |
| 72 | - ? (bool) $block_editor_dark_mode | |
| 73 | - : (bool) $enable_admin_panel_dark_mode; | |
| 74 | - | |
| 75 | - // Darkify's own settings/help screens additionally load it even while | |
| 76 | - // the option is OFF, so flipping "Admin Panel Dark Mode" in the React | |
| 77 | - // admin can show the admin-bar icon (and have it actually work) | |
| 78 | - // immediately instead of only after a reload. Loading it here cannot | |
| 79 | - // darken anything on its own: both the FOUC snippet in | |
| 80 | - // header_script.php and darkify_check_preloading() in client_main.js | |
| 81 | - // are gated on `darkify_admin_panel_dark_enabled`. | |
| 82 | - if ($needs_engine || $this->is_darkify_spa_page()) { | |
| 83 | - add_action('admin_bar_menu', array($this, 'darkify_admin_bar_switch'), 9999); | |
| 84 | - add_action('admin_print_scripts', array($this, 'darkify_admin_header_script'), 1); | |
| 85 | - add_action('admin_footer', array($this, 'darkify_admin_footer_script')); | |
| 86 | - } | |
| 87 | - }); | |
| 88 | - | |
| 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')); | |
| 89 | 87 | new ReviewNotice(); |
| 90 | 88 | new DBUpdates(); |
| 91 | - if (! defined('THEMEATELIER_OFFER_BANNER_LOADED')) { | |
| 92 | - define('THEMEATELIER_OFFER_BANNER_LOADED', true); | |
| 93 | - ThemeAtelier_Offer_Banner::instance(); | |
| 94 | - } | |
| 95 | - | |
| 96 | 89 | add_action('after_setup_theme', array($this, 'init_components')); |
| 97 | 90 | add_filter('autoptimize_filter_js_exclude', array($this, 'darkify_exclude_js_from_cache_plugins')); |
| 98 | - add_action('admin_init', [$this, 'load_classic_editor_scripts']); | |
| 99 | - add_filter('admin_footer_text', array($this, 'darkify_admin_footer'), 1, 2); | |
| 100 | - $active_plugins = get_option('active_plugins'); | |
| 101 | - foreach ($active_plugins as $active_plugin) { | |
| 102 | - $_temp = strpos($active_plugin, 'darkify.php'); | |
| 103 | - if (false != $_temp) { | |
| 104 | - add_filter('plugin_action_links_' . DARKIFY_BASENAME, array($this, 'add_plugin_action_links'), 10, 2); | |
| 105 | - add_filter('plugin_row_meta', array($this, 'after_darkify_row_meta'), 10, 4); | |
| 106 | - } | |
| 107 | - } | |
| 108 | 91 | } |
| 109 | 92 | |
| 110 | - public function init_components() | |
| 111 | - { | |
| 93 | + public function init_components() { | |
| 112 | 94 | DarkifyOptions::options('darkify'); |
| 113 | 95 | } |
| 114 | 96 | |
| 115 | - /** | |
| 116 | - * Whether the current screen is one of Darkify's own React SPA screens | |
| 117 | - * (Settings / Get Help) — the only place the Admin Panel Dark Mode option can | |
| 118 | - * be toggled, and therefore the only place that needs the engine loaded up | |
| 119 | - * front so the admin-bar icon can react instantly. | |
| 120 | - */ | |
| 121 | - public function is_darkify_spa_page(): bool | |
| 122 | - { | |
| 123 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only screen check. | |
| 124 | - $page = isset($_GET['page']) ? \sanitize_key(\wp_unslash($_GET['page'])) : ''; | |
| 125 | - return \in_array($page, Assets::SPA_SLUGS, true); | |
| 126 | - } | |
| 127 | - | |
| 128 | 97 | public function darkify_exclude_js_from_cache_plugins($excludes) |
| 129 | 98 | { |
| 130 | 99 | $excludes .= ',client_main.js,client_main.min.js'; |
| 131 | 100 | return $excludes; |
| @@ -130,24 +99,19 @@ | ||
| 130 | 99 | $excludes .= ',client_main.js,client_main.min.js'; |
| 131 | 100 | return $excludes; |
| 132 | 101 | } |
| 133 | 102 | |
| 134 | - public function enqueue_styles() | |
| 103 | + public function enqueue_styles($hook) | |
| 135 | 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 | + | |
| 136 | 109 | $options = get_option('darkify'); |
| 137 | 110 | $enable_admin_panel_dark_mode = isset($options["enable_admin_panel_dark_mode"]) ? $options["enable_admin_panel_dark_mode"] : false; |
| 138 | - // Block Editor Dark Mode darkens the editor independently of Admin Panel | |
| 139 | - // Dark Mode, so the stylesheet must load there too. | |
| 140 | - $block_editor_dark_mode = isset($options['block_editor_dark_mode']) ? $options['block_editor_dark_mode'] : false; | |
| 141 | - $screen = \function_exists('get_current_screen') ? \get_current_screen() : null; | |
| 142 | - $is_block_editor = $screen && \method_exists($screen, 'is_block_editor') && $screen->is_block_editor(); | |
| 143 | - $allow_admin_dark = $enable_admin_panel_dark_mode || ($is_block_editor && $block_editor_dark_mode); | |
| 144 | - // Darkify's own screens always get the stylesheet so the admin-bar icon | |
| 145 | - // can be revealed the moment the option is switched on. It only styles | |
| 146 | - // `.darkify_*` classes, so it is inert until the engine adds them. | |
| 147 | - if (($allow_admin_dark || $this->is_darkify_spa_page()) && $this->darkify_is_dark_mode_allowed()) { | |
| 111 | + if ($enable_admin_panel_dark_mode) { | |
| 148 | 112 | if (!wp_style_is('darkify-admin-switch', 'enqueued')) { |
| 149 | - 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'); | |
| 113 | + wp_enqueue_style('darkify-admin-switch', DARKIFY_DIR_URL . 'src/assets/css/client_main' . $this->min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 150 | 114 | } |
| 151 | 115 | } |
| 152 | 116 | // Review notice CSS |
| 153 | 117 | wp_enqueue_style('darkify-review-notice', DARKIFY_DIR_URL . 'src/Admin/ReviewNotice/assets/css/review-notice' . $this->min . '.css', array(), DARKIFY_VERSION, 'all'); |
| @@ -156,258 +120,87 @@ | ||
| 156 | 120 | public function enqueue_scripts($hook) |
| 157 | 121 | { |
| 158 | 122 | $options = get_option('darkify'); |
| 159 | 123 | $enable_admin_panel_dark_mode = isset($options["enable_admin_panel_dark_mode"]) ? $options["enable_admin_panel_dark_mode"] : false; |
| 160 | - $is_spa = $this->is_darkify_spa_page(); | |
| 161 | - if (! $this->darkify_is_dark_mode_allowed()) { | |
| 162 | - return; | |
| 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); | |
| 163 | 126 | } |
| 164 | 127 | |
| 165 | - // Mirror the `current_screen` engine-load rule exactly, so the engine is | |
| 166 | - // only enqueued where its inline config (header_script.php) is ALSO | |
| 167 | - // printed. Block Editor Dark Mode is independent of Admin Panel Dark | |
| 168 | - // Mode: the block editor loads the engine when Block Editor Dark Mode is | |
| 169 | - // on (regardless of Admin Panel Dark Mode); every other admin screen | |
| 170 | - // keys on Admin Panel Dark Mode. (A SPA screen always gets the config.) | |
| 171 | - if (! $is_spa) { | |
| 172 | - $screen = \function_exists('get_current_screen') ? \get_current_screen() : null; | |
| 173 | - $is_block_editor = $screen && \method_exists($screen, 'is_block_editor') && $screen->is_block_editor(); | |
| 174 | - $block_editor_dark_mode = isset($options['block_editor_dark_mode']) ? $options['block_editor_dark_mode'] : false; | |
| 175 | - $allow = $is_block_editor ? (bool) $block_editor_dark_mode : (bool) $enable_admin_panel_dark_mode; | |
| 176 | - if (! $allow) { | |
| 177 | - return; | |
| 178 | - } | |
| 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); | |
| 179 | 130 | } |
| 180 | - | |
| 181 | - wp_enqueue_script( | |
| 182 | - 'darkify-admin-client-main', | |
| 183 | - DARKIFY_DIR_URL . 'src/assets/js/client_main' . $this->min . '.js', | |
| 184 | - array(), | |
| 185 | - $this->darkify_asset_version('src/assets/js/client_main' . $this->min . '.js') | |
| 186 | - ); | |
| 187 | 131 | } |
| 188 | 132 | |
| 189 | - /** | |
| 190 | - * Cache-busting version for a bundled asset: the plugin version plus the | |
| 191 | - * file's mtime, so rebuilding client_main.js/.css (which does NOT bump the | |
| 192 | - * plugin version) still changes the URL and browsers fetch the new file | |
| 193 | - * instead of serving a stale one. Mirrors Admin\Assets::asset_version(). | |
| 194 | - */ | |
| 195 | - public function darkify_asset_version(string $relative_path): string | |
| 196 | - { | |
| 197 | - $abs = DARKIFY_PATH . $relative_path; | |
| 198 | - $mtime = \is_readable($abs) ? \filemtime($abs) : false; | |
| 199 | - return $mtime ? DARKIFY_VERSION . '.' . $mtime : DARKIFY_VERSION; | |
| 200 | - } | |
| 201 | - | |
| 202 | - /* | |
| 203 | - Dequeue Darkify scripts and styles on specific admin pages (e.g., MainWP pages) | |
| 204 | - */ | |
| 205 | - | |
| 206 | - public function admin_dequeue_for_specefic_pages() | |
| 207 | - { | |
| 208 | - $page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : ''; | |
| 209 | - $dequeue_pages = array( | |
| 210 | - 'mainwp_tab', | |
| 211 | - 'managesites', | |
| 212 | - 'ManageClients', | |
| 213 | - 'CostSummary', | |
| 214 | - 'InsightsOverview', | |
| 215 | - 'Extensions', | |
| 216 | - 'RESTAPI', | |
| 217 | - 'mainwp-setup', | |
| 218 | - 'ThemesManage', | |
| 219 | - 'PluginsManage', | |
| 220 | - 'InsightsManage', | |
| 221 | - 'ManageGroups', | |
| 222 | - 'UpdatesManage', | |
| 223 | - 'PluginsInstall', | |
| 224 | - 'PluginsAutoUpdate', | |
| 225 | - 'PluginsIgnore', | |
| 226 | - 'PluginsAbandoned', | |
| 227 | - 'PluginsIgnoredAbandoned', | |
| 228 | - 'ThemesInstall', | |
| 229 | - 'ThemesAutoUpdate', | |
| 230 | - 'ThemesIgnore', | |
| 231 | - 'ThemesAbandoned', | |
| 232 | - 'ThemesIgnoredAbandoned', | |
| 233 | - 'UserBulkManage', | |
| 234 | - 'UserBulkAdd', | |
| 235 | - 'BulkImportUsers', | |
| 236 | - 'UpdateAdminPasswords', | |
| 237 | - 'PostBulkManage', | |
| 238 | - 'Extensions-Mainwp-Backups', | |
| 239 | - 'Extensions-Mainwp-Security', | |
| 240 | - 'Extensions-Mainwp-Analytics', | |
| 241 | - 'Mainwp-Monitoring', | |
| 242 | - 'Extensions-Mainwp-Agency', | |
| 243 | - 'Extensions-Mainwp-Administrative', | |
| 244 | - 'Extensions-Mainwp-Development', | |
| 245 | - 'Extensions-Mainwp-Performance', | |
| 246 | - 'ClientAddNew', | |
| 247 | - 'ClientImport', | |
| 248 | - 'ManageCostTracker', | |
| 249 | - 'CostTrackerAdd', | |
| 250 | - 'AddApiKeys', | |
| 251 | - ); | |
| 252 | - | |
| 253 | - | |
| 254 | - if (in_array($page, $dequeue_pages, true)) { | |
| 255 | - wp_deregister_style('darkify-admin-switch'); | |
| 256 | - wp_dequeue_script('darkify-admin-client-main'); | |
| 257 | - } | |
| 258 | - } | |
| 259 | - | |
| 260 | - /** | |
| 261 | - * Replace wp-admin's footer credit with Darkify's review request, on | |
| 262 | - * Darkify's own screens only. | |
| 263 | - * | |
| 264 | - * Screens are matched by page slug (`is_darkify_spa_page()`) rather than by | |
| 265 | - * a hardcoded screen id, so both the Settings and Get Help SPA screens match | |
| 266 | - * and the check keeps working if the menu is ever retitled. The slug list is | |
| 267 | - * the same source of truth the assets already load from. | |
| 268 | - * | |
| 269 | - * @param string $text Existing footer text. | |
| 270 | - * | |
| 271 | - * @return string | |
| 272 | - */ | |
| 273 | - public function darkify_admin_footer($text) | |
| 274 | - { | |
| 275 | - if (! $this->is_darkify_spa_page()) { | |
| 276 | - return $text; | |
| 277 | - } | |
| 278 | - | |
| 279 | - return sprintf( | |
| 280 | - /* translators: 1: start strong tag, 2: close strong tag. 3: start link 4: close link */ | |
| 281 | - __('<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'), | |
| 282 | - '<strong>', | |
| 283 | - '</strong>', | |
| 284 | - '<span class="greet-footer-text-star">★★★★★</span> <a href="https://wordpress.org/support/plugin/darkify/reviews/#new-post" target="_blank" rel="noopener noreferrer">', | |
| 285 | - '</a>' | |
| 286 | - ); | |
| 287 | - } | |
| 288 | - | |
| 289 | 133 | // Plugin settings in plugin list |
| 290 | 134 | public function add_plugin_action_links(array $links) |
| 291 | 135 | { |
| 292 | 136 | $new_links = array( |
| 293 | 137 | sprintf('<a href="' . esc_url(admin_url('admin.php?page=darkify')) . '">' . esc_html__('Settings', 'darkify') . '</a>'), |
| 294 | - sprintf('<a target="_blank" href="https://wordpress.org/support/plugin/darkify/">' . esc_html__('Support', '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>'), | |
| 295 | 140 | ); |
| 296 | - | |
| 297 | - $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')); | |
| 298 | - | |
| 299 | 141 | return array_merge($new_links, $links); |
| 300 | 142 | } |
| 301 | 143 | |
| 302 | - /** | |
| 303 | - * Add plugin row meta link. | |
| 304 | - * | |
| 305 | - * @since 2.0 | |
| 306 | - * | |
| 307 | - * @param array $plugin_meta . | |
| 308 | - * @param string $file . | |
| 309 | - * | |
| 310 | - * @return array | |
| 311 | - */ | |
| 312 | - public function after_darkify_row_meta($plugin_meta, $file) | |
| 313 | - { | |
| 314 | 144 | |
| 315 | - if (DARKIFY_BASENAME === $file) { | |
| 316 | - $plugin_meta[] = '<a href="' . DARKIFY_DEMO_URL . '" target="_blank">' . __('Live Demo', 'darkify') . '</a>'; | |
| 317 | - } | |
| 318 | - | |
| 319 | - return $plugin_meta; | |
| 320 | - } | |
| 321 | - | |
| 322 | 145 | public function darkify_admin_bar_switch($wp_admin_bar) |
| 323 | 146 | { |
| 324 | - if (! $this->darkify_is_dark_mode_allowed()) { | |
| 325 | - return; | |
| 326 | - } | |
| 327 | - | |
| 328 | - $options = get_option('darkify'); | |
| 329 | - $enable_admin_panel_dark_mode = isset($options['enable_admin_panel_dark_mode']) ? $options['enable_admin_panel_dark_mode'] : false; | |
| 330 | - | |
| 331 | - // Everywhere but Darkify's own screens the node is only registered when | |
| 332 | - // the option is on, so it is always visible. On the SPA screens it is | |
| 333 | - // registered regardless and starts hidden while the option is off — the | |
| 334 | - // React admin then just flips this class (see WpAdminBarBridge), which is | |
| 335 | - // what makes the icon appear/disappear without a reload. | |
| 336 | - $classes = 'darkify_admin_bar_switch_container'; | |
| 337 | - if (! $enable_admin_panel_dark_mode) { | |
| 338 | - $classes .= ' darkify_admin_bar_hidden'; | |
| 339 | - } | |
| 340 | - | |
| 341 | - $wp_admin_bar->add_node(array( | |
| 147 | + $args = array( | |
| 342 | 148 | 'parent' => 'top-secondary', |
| 343 | 149 | 'id' => 'darkify_admin_bar_switch_container', |
| 344 | 150 | 'meta' => array( |
| 345 | - 'class' => $classes, | |
| 151 | + 'class' => 'darkify_admin_bar_switch_container', | |
| 346 | 152 | 'onclick' => 'darkify_switch_trigger()', |
| 347 | - ), | |
| 348 | - )); | |
| 153 | + ) | |
| 154 | + ); | |
| 155 | + $wp_admin_bar->add_node($args); | |
| 349 | 156 | } |
| 350 | 157 | |
| 351 | - public function darkify_is_dark_mode_allowed() | |
| 352 | - { | |
| 353 | - | |
| 354 | - $options = get_option('darkify'); | |
| 355 | - $options = is_array($options) ? $options : array(); | |
| 356 | - // Guarded read: `disallowed_admin_pages` has no schema default, so the | |
| 357 | - // React settings save doesn't persist it until the field is used. Reading | |
| 358 | - // it unguarded would emit an "Undefined array key" warning on every | |
| 359 | - // dark-mode hook (see the Pro plugin's Admin.php for the full story). | |
| 360 | - $disallowed_admin_pages = isset($options['disallowed_admin_pages']) ? $options['disallowed_admin_pages'] : ''; | |
| 361 | - /* Disable on Disallowed Admin Plugins */ | |
| 362 | - if ($this->utils->isRestrictedByDisallowedAdminPages($disallowed_admin_pages)) { | |
| 363 | - return False; | |
| 364 | - } | |
| 365 | - return True; | |
| 366 | - } | |
| 367 | - | |
| 368 | 158 | public function darkify_admin_header_script() |
| 369 | 159 | { |
| 370 | - if ($this->darkify_is_dark_mode_allowed()) { | |
| 371 | - include_once DarkifyUtils::darkify_locate_template('header_script.php'); | |
| 372 | - } | |
| 160 | + include_once DarkifyUtils::darkify_locate_template('header_script.php'); | |
| 373 | 161 | } |
| 374 | 162 | |
| 375 | 163 | public function darkify_admin_footer_script() |
| 376 | 164 | { |
| 377 | - if ($this->darkify_is_dark_mode_allowed()) { | |
| 378 | - include_once DarkifyUtils::darkify_locate_template('footer_script.php'); | |
| 379 | - } | |
| 165 | + include_once DarkifyUtils::darkify_locate_template('footer_script.php'); | |
| 380 | 166 | } |
| 381 | 167 | |
| 382 | - /** | |
| 383 | - * Load classic editor scripts. | |
| 384 | - * | |
| 385 | - * @since 5.0.0 | |
| 386 | - */ | |
| 387 | - public function load_classic_editor_scripts() | |
| 168 | + public function add_plugin_page() | |
| 388 | 169 | { |
| 389 | - $options = get_option('darkify'); | |
| 390 | - $classic_editor_dark_mode = isset($options['classic_editor_dark_mode']) ? $options['classic_editor_dark_mode'] : ''; | |
| 391 | - if (! current_user_can('edit_posts') && ! current_user_can('edit_pages')) { | |
| 392 | - return; | |
| 393 | - } | |
| 394 | - if (get_user_option('rich_editing') !== 'true') { | |
| 395 | - return; | |
| 396 | - } | |
| 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!', 'darkify')), | |
| 198 | + 'manage_options', | |
| 199 | + 'https://darkifywp.com/pricing/?ref=1' | |
| 200 | + ); | |
| 201 | + do_action('darkify_after_upgrade_pro_menu'); | |
| 202 | + } | |
| 397 | 203 | |
| 398 | - // Bail if admin_classic_editor is not enabled. | |
| 399 | - if (! wp_validate_boolean($classic_editor_dark_mode)) { | |
| 400 | - return; | |
| 401 | - } | |
| 204 | + public function darkify_settings() {} | |
| 402 | 205 | |
| 403 | - add_filter('mce_external_plugins', function ($plugins) { | |
| 404 | - $plugins['darkify_button'] = plugins_url('src/assets/js/admin-classic-editor.js', DARKIFY_FILE); | |
| 405 | - return $plugins; | |
| 406 | - }); | |
| 407 | - | |
| 408 | - add_filter('mce_buttons', function ($buttons) { | |
| 409 | - $buttons[] = 'darkify_button'; | |
| 410 | - return $buttons; | |
| 411 | - }); | |
| 412 | - } | |
| 413 | 206 | } |