", { rel: "stylesheet", id: styleData.id, href: styleData.url, type: "text/css" }); // Add new style at the end of head $("head").append($newStyle); // Remove old styles after a short delay to ensure new one loads setTimeout(function() { $oldStyles.remove(); }, 100); }); } else { console.error("Error getting color scheme data:", response); } }, error: function(xhr, status, error) { console.error("AJAX error:", error); } }); } }); '; wp_add_inline_script('wp-allstars-admin', $color_js); } /** * Set the admin color scheme based on the setting value */ public function set_admin_color_scheme() { // Get current user $user_id = get_current_user_id(); if (!$user_id) { return; } // Check if our setting is enabled $modern_colors_enabled = get_option($this->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); } /** * AJAX handler to get the admin color scheme stylesheets */ public function get_admin_colors_ajax() { // Verify nonce check_ajax_referer('wp-allstars-nonce', '_wpnonce'); // Get current user ID $user_id = get_current_user_id(); if (!$user_id) { wp_send_json_error('Not logged in'); return; } // Determine which scheme to set based on the value $enable_modern = isset($_POST['enable_modern']) && $_POST['enable_modern'] == 1; $scheme = $enable_modern ? $this->modern_scheme : $this->default_scheme; // Get color scheme information global $_wp_admin_css_colors; // Make sure the scheme exists if (!isset($_wp_admin_css_colors[$scheme])) { wp_send_json_error('Color scheme not found'); return; } // Get the stylesheet URLs $color_scheme = $_wp_admin_css_colors[$scheme]; $stylesheet_urls = array(); // Colors stylesheet $stylesheet_urls[] = array( 'id' => 'colors', 'url' => $color_scheme->url . 'colors.min.css' ); // Colors RTL stylesheet if needed if (is_rtl() && file_exists($color_scheme->url . 'colors-rtl.min.css')) { $stylesheet_urls[] = array( 'id' => 'colors-rtl', 'url' => $color_scheme->url . 'colors-rtl.min.css' ); } // Return the URLs to the JavaScript wp_send_json_success($stylesheet_urls); } }