From 5edc8c84679447752480bc8cd6f7261bfac8feed Mon Sep 17 00:00:00 2001 From: Marcus Quinn Date: Tue, 25 Mar 2025 02:51:34 +0000 Subject: [PATCH] Add Modern Admin Colors feature to customize admin color scheme --- admin/includes/class-settings-manager.php | 6 +- includes/class-wp-allstars-admin-colors.php | 98 +++++++++++++++++++++ wp-allstars-plugin.php | 12 ++- 3 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 includes/class-wp-allstars-admin-colors.php diff --git a/admin/includes/class-settings-manager.php b/admin/includes/class-settings-manager.php index e2170a3..3ad003b 100644 --- a/admin/includes/class-settings-manager.php +++ b/admin/includes/class-settings-manager.php @@ -71,7 +71,7 @@ class WP_Allstars_Settings_Manager { ?>
- +
@@ -86,12 +86,12 @@ class WP_Allstars_Settings_Manager {

- +

diff --git a/includes/class-wp-allstars-admin-colors.php b/includes/class-wp-allstars-admin-colors.php new file mode 100644 index 0000000..02fe973 --- /dev/null +++ b/includes/class-wp-allstars-admin-colors.php @@ -0,0 +1,98 @@ +option_name, false); + + // Get the scheme to set + $scheme = $modern_colors_enabled ? $this->modern_scheme : $this->default_scheme; + + // Update user meta to set the color scheme + update_user_meta($user_id, 'admin_color', $scheme); + } + + /** + * Handle color scheme update via AJAX + * Runs early to apply the color scheme change before the general option update handler + */ + public function handle_color_scheme_update() { + // Check for required params + if (!isset($_POST['option']) || !isset($_POST['value'])) { + return; + } + + // Only process our specific option + if ($_POST['option'] !== $this->option_name) { + return; + } + + // Get the current user ID + $user_id = get_current_user_id(); + if (!$user_id) { + return; + } + + // Determine which scheme to set based on the value + $value = (bool) $_POST['value']; + $scheme = $value ? $this->modern_scheme : $this->default_scheme; + + // Update the user's color scheme + update_user_meta($user_id, 'admin_color', $scheme); + } +} \ No newline at end of file diff --git a/wp-allstars-plugin.php b/wp-allstars-plugin.php index efdea80..b265b00 100644 --- a/wp-allstars-plugin.php +++ b/wp-allstars-plugin.php @@ -46,6 +46,7 @@ register_activation_hook(__FILE__, 'wp_allstars_activate'); * Load core plugin components */ require_once plugin_dir_path(__FILE__) . 'includes/class-wp-allstars-auto-upload.php'; +require_once plugin_dir_path(__FILE__) . 'includes/class-wp-allstars-admin-colors.php'; // Load admin-specific components if (is_admin()) { @@ -72,8 +73,6 @@ if (is_admin()) { require_once plugin_dir_path(__FILE__) . 'admin/settings.php'; } - - /** * Auto Upload feature initialization * @@ -87,6 +86,15 @@ function wp_allstars_init_auto_upload() { } add_action('init', 'wp_allstars_init_auto_upload'); +/** + * Initialize core features + */ +function wp_allstars_init_features() { + // Initialize the Admin Colors feature + new WP_Allstars_Admin_Colors(); +} +add_action('plugins_loaded', 'wp_allstars_init_features'); + /** * Initialize core plugin classes */