'boolean', 'description' => __('Whether dark mode is enabled for the user', 'abovewp-admin-dark-mode'), 'single' => true, 'show_in_rest' => true, )); // Add plugin card to AboveWP dashboard add_action('abovewp_admin_dashboard_plugins', array($this, 'display_plugin_card')); } /** * Enqueue admin scripts and styles */ public function enqueue_admin_assets() { // Enqueue CSS wp_enqueue_style( 'abovewp-admin-dark-mode', ABOVEWP_ADM_PLUGIN_URL . 'assets/css/dark-mode.css', array(), ABOVEWP_ADM_VERSION ); // Enqueue JS wp_enqueue_script( 'abovewp-admin-dark-mode', ABOVEWP_ADM_PLUGIN_URL . 'assets/js/dark-mode.js', array('jquery'), ABOVEWP_ADM_VERSION, true ); // Pass data to JS wp_localize_script( 'abovewp-admin-dark-mode', 'abovewpDarkMode', array( 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('abovewp_dark_mode_nonce'), 'isDarkMode' => get_user_meta(get_current_user_id(), 'abovewp_dark_mode_enabled', true) === '1', 'darkModeText' => __('Dark Mode', 'abovewp-admin-dark-mode'), 'lightModeText' => __('Light Mode', 'abovewp-admin-dark-mode'), ) ); } /** * Add dark mode toggle to admin bar */ public function add_dark_mode_toggle($wp_admin_bar) { $wp_admin_bar->add_node(array( 'id' => 'abovewp-dark-mode-toggle', 'title' => '' . __('Dark Mode', 'abovewp-admin-dark-mode') . '', 'href' => '#', 'meta' => array( 'class' => 'abovewp-dark-mode-toggle', 'title' => __('Toggle Dark Mode', 'abovewp-admin-dark-mode'), ), )); } /** * Add dark mode class to body early */ public function add_dark_mode_class() { if (get_user_meta(get_current_user_id(), 'abovewp_dark_mode_enabled', true) === '1') { add_filter('admin_body_class', function($classes) { return $classes . ' abovewp-dark-mode'; }); } } /** * Remove WordPress admin notices on plugin pages */ public function remove_admin_notices_on_plugin_pages() { $screen = get_current_screen(); // Only remove notices on our plugin pages if (isset($screen->id) && ( strpos($screen->id, 'abovewp-admin-dark-mode') !== false || strpos($screen->id, 'toplevel_page_abovewp') !== false )) { // Remove all admin notices remove_all_actions('admin_notices'); remove_all_actions('all_admin_notices'); // Add our custom CSS to hide any notices that might get through echo ''; } } /** * Display plugin card on AboveWP dashboard */ public function display_plugin_card() { ?>