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

View File

@ -461,33 +461,49 @@ function wp_allstars_ajax_get_themes() {
return; return;
} }
// Add debugging
error_log('WP ALLSTARS: Starting theme fetch process'); error_log('WP ALLSTARS: Starting theme fetch process');
try { try {
error_log('WP ALLSTARS: Fetching theme data for kadence'); error_log('WP ALLSTARS: Fetching theme data for kadence');
// Get theme data with minimal fields // Check if we have cached data first
$theme_data = themes_api('theme_information', array( $theme_data = wp_allstars_get_cached_theme();
'slug' => 'kadence',
'fields' => array( // If no cached data, fetch from API
'sections' => false, if (empty($theme_data)) {
'description' => true, error_log('WP ALLSTARS: No cached theme data, fetching from API');
'rating' => true,
'ratings' => false, // Get theme data with minimal fields
'downloaded' => true, $theme_data = themes_api('theme_information', array(
'download_link' => true, 'slug' => 'kadence',
'last_updated' => true, 'fields' => array(
'homepage' => true, 'sections' => false,
'tags' => false, 'description' => true,
'screenshot_url' => true, 'rating' => true,
'version' => true, 'ratings' => false,
'requires' => true, 'downloaded' => true,
'requires_php' => true, 'download_link' => true,
'active_installs' => true, 'last_updated' => true,
'author' => true, 'homepage' => true,
'preview_url' => true, 'tags' => false,
) 'screenshot_url' => true,
)); 'version' => true,
'requires' => true,
'requires_php' => true,
'active_installs' => true,
'author' => true,
'preview_url' => true,
)
));
// 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)) { if (is_wp_error($theme_data)) {
error_log('WP ALLSTARS Theme API Error: ' . $theme_data->get_error_message()); error_log('WP ALLSTARS Theme API Error: ' . $theme_data->get_error_message());