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>
<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>
</div>
</div>

View File

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