diff --git a/admin/js/wp-allstars-admin.js b/admin/js/wp-allstars-admin.js index a912e84..f5ff53d 100644 --- a/admin/js/wp-allstars-admin.js +++ b/admin/js/wp-allstars-admin.js @@ -205,14 +205,13 @@ jQuery(document).ready(function($) { loadTheme = function() { var $container = $('#wpa-theme-list'); - // Create loading overlay with clear visual indicator - var loadingHTML = '

Loading themes...

'; + // 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 = $('
'); + $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('

Failed to load themes. Please try again. Error: ' + error + '

'); console.error('AJAX Error:', xhr.responseText); diff --git a/admin/settings.php b/admin/settings.php index a7451fb..dcbcef6 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -461,33 +461,49 @@ 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'); - // Get theme data with minimal fields - $theme_data = themes_api('theme_information', array( - 'slug' => 'kadence', - 'fields' => array( - 'sections' => false, - 'description' => true, - 'rating' => true, - 'ratings' => false, - 'downloaded' => true, - 'download_link' => true, - 'last_updated' => true, - 'homepage' => true, - 'tags' => false, - 'screenshot_url' => true, - 'version' => true, - 'requires' => true, - 'requires_php' => true, - 'active_installs' => true, - 'author' => true, - 'preview_url' => true, - ) - )); + // 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', + 'fields' => array( + 'sections' => false, + 'description' => true, + 'rating' => true, + 'ratings' => false, + 'downloaded' => true, + 'download_link' => true, + 'last_updated' => true, + 'homepage' => 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)) { error_log('WP ALLSTARS Theme API Error: ' . $theme_data->get_error_message());