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,24 +86,38 @@ 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\']";
// Create a new link element var $oldStyles = $(colorStyleSelector);
var $newStyle = $("<link>", {
rel: "stylesheet", console.log("Found color stylesheets:", $oldStyles.length);
id: styleData.id,
href: styleData.url, // Create a new link element
type: "text/css" var $newStyle = $("<link>", {
}); rel: "stylesheet",
id: styleData.id,
// Replace the old style with the new one href: styleData.url,
$oldStyle.after($newStyle); type: "text/css"
$oldStyle.remove(); });
}
// 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);
} }
}); });
} }