Update Modern Admin Colors description and fix color scheme toggle functionality

This commit is contained in:
Marcus Quinn
2025-03-25 02:57:25 +00:00
parent 1654355939
commit 223b0f6922
2 changed files with 30 additions and 17 deletions

View File

@ -91,7 +91,7 @@ class WP_Allstars_Settings_Manager {
</div> </div>
</div> </div>
<p class="wp-setting-description"> <p class="wp-setting-description">
<?php esc_html_e('Switch to the Modern Admin colour scheme, to remind that you\'re using an SEO Pro Stack :)', 'wp-allstars'); ?> <?php esc_html_e('Switch to the Modern Admin colours, to remind that you\'re using an SEO Pro Stack :)', 'wp-allstars'); ?>
</p> </p>
</div> </div>
</div> </div>

View File

@ -73,8 +73,7 @@ class WP_Allstars_Admin_Colors {
// Function to dynamically apply admin color scheme // Function to dynamically apply admin color scheme
function applyAdminColorScheme(enableModern) { function applyAdminColorScheme(enableModern) {
// Get the stylesheets we need to replace console.log("Applying admin color scheme:", enableModern ? "modern" : "default");
var $adminColors = $("link[href*=\'colors\']");
// AJAX request to get the new color scheme URLs // AJAX request to get the new color scheme URLs
$.ajax({ $.ajax({
@ -87,10 +86,16 @@ class WP_Allstars_Admin_Colors {
}, },
success: function(response) { success: function(response) {
if (response.success && response.data) { if (response.success && response.data) {
console.log("Received color scheme data:", response.data);
// Replace the stylesheets // Replace the stylesheets
$.each(response.data, function(index, styleData) { $.each(response.data, function(index, styleData) {
var $oldStyle = $("link[href*=\'" + styleData.id + "\']"); // Find any style with "colors" in the URL or ID
if ($oldStyle.length) { var colorStyleSelector = "link[href*=\'colors\'], link[id*=\'colors\']";
var $oldStyles = $(colorStyleSelector);
console.log("Found color stylesheets:", $oldStyles.length);
// Create a new link element // Create a new link element
var $newStyle = $("<link>", { var $newStyle = $("<link>", {
rel: "stylesheet", rel: "stylesheet",
@ -99,12 +104,20 @@ class WP_Allstars_Admin_Colors {
type: "text/css" type: "text/css"
}); });
// Replace the old style with the new one // Add new style at the end of head
$oldStyle.after($newStyle); $("head").append($newStyle);
$oldStyle.remove();
} // 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);
} }
}); });
} }