Fix theme tab loading issue with improved error handling and caching

This commit is contained in:
Marcus Quinn
2025-03-16 19:01:32 +00:00
parent b4dbd01519
commit 31a68c0333
2 changed files with 49 additions and 28 deletions

View File

@ -205,14 +205,13 @@ jQuery(document).ready(function($) {
loadTheme = function() {
var $container = $('#wpa-theme-list');
// Create loading overlay with clear visual indicator
var loadingHTML = '<div class="wp-allstars-loading-overlay" id="theme-loading-overlay"><span class="spinner is-active"></span><p>Loading themes...</p></div>';
// Clear existing content
$container.empty();
// Clear existing content and add loading overlay
$container.empty().html(loadingHTML);
// Ensure container has relative positioning for the overlay
// Show loading overlay
$container.css('position', 'relative');
var $loadingOverlay = $('<div class="wp-allstars-loading-overlay"><span class="spinner is-active"></span></div>');
$container.append($loadingOverlay);
// AJAX request to get themes
$.ajax({
@ -223,6 +222,9 @@ jQuery(document).ready(function($) {
_wpnonce: wpAllstars.nonce
},
success: function(response) {
// Remove loading overlay
$loadingOverlay.remove();
if (response.success) {
// Replace all content with new HTML
$container.html(response.data);
@ -235,6 +237,9 @@ jQuery(document).ready(function($) {
}
},
error: function(xhr, status, error) {
// Remove loading overlay
$loadingOverlay.remove();
// Show error message
$container.html('<div class="notice notice-error"><p>Failed to load themes. Please try again. Error: ' + error + '</p></div>');
console.error('AJAX Error:', xhr.responseText);

View File

@ -461,11 +461,19 @@ function wp_allstars_ajax_get_themes() {
return;
}
// Add debugging
error_log('WP ALLSTARS: Starting theme fetch process');
try {
error_log('WP ALLSTARS: Fetching theme data for kadence');
// Check if we have cached data first
$theme_data = wp_allstars_get_cached_theme();
// If no cached data, fetch from API
if (empty($theme_data)) {
error_log('WP ALLSTARS: No cached theme data, fetching from API');
// Get theme data with minimal fields
$theme_data = themes_api('theme_information', array(
'slug' => 'kadence',
@ -489,6 +497,14 @@ function wp_allstars_ajax_get_themes() {
)
));
// Cache the result if successful
if (!is_wp_error($theme_data)) {
wp_allstars_set_cached_theme($theme_data);
}
} else {
error_log('WP ALLSTARS: Using cached theme data');
}
if (is_wp_error($theme_data)) {
error_log('WP ALLSTARS Theme API Error: ' . $theme_data->get_error_message());
wp_send_json_error('Theme API Error: ' . $theme_data->get_error_message());