Fix theme tab loading issue with improved error handling and caching
This commit is contained in:
@ -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);
|
||||
|
@ -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());
|
||||
|
Reference in New Issue
Block a user