From 479934b6c38bb599a423a6a44068f4b0e771a5d0 Mon Sep 17 00:00:00 2001 From: Marcus Quinn Date: Sun, 16 Mar 2025 19:08:13 +0000 Subject: [PATCH] Fix theme tab loading by using the same inline script approach as the plugins tab --- admin/js/wp-allstars-admin.js | 57 ++--------------------------------- admin/settings.php | 43 ++++++++++++++++++++------ 2 files changed, 35 insertions(+), 65 deletions(-) diff --git a/admin/js/wp-allstars-admin.js b/admin/js/wp-allstars-admin.js index 992dedb..4907580 100644 --- a/admin/js/wp-allstars-admin.js +++ b/admin/js/wp-allstars-admin.js @@ -201,61 +201,8 @@ jQuery(document).ready(function($) { } - // Function to load themes - global function - window.loadTheme = function() { - console.log('Starting theme loading process'); - var $container = $('#wpa-theme-list'); - - // Clear existing content - $container.empty(); - console.log('Container emptied'); - - // Show loading overlay - $container.css('position', 'relative'); - var $loadingOverlay = $('
'); - $container.append($loadingOverlay); - console.log('Loading overlay added'); - - // AJAX request to get themes - console.log('Sending AJAX request with nonce:', wpAllstars.nonce); - $.ajax({ - url: ajaxurl, - type: 'POST', - data: { - action: 'wp_allstars_get_themes', - _wpnonce: wpAllstars.nonce - }, - success: function(response) { - console.log('AJAX success response:', response); - // Remove loading overlay - $loadingOverlay.remove(); - - if (response.success) { - console.log('Response success, updating container HTML'); - // Replace all content with new HTML - $container.html(response.data); - - // Initialize theme action buttons - console.log('Initializing theme handlers'); - initThemeHandlers(); - } else { - console.error('Response indicates error:', response.data); - // Show error message - $container.html('

' + response.data + '

'); - } - }, - error: function(xhr, status, error) { - console.error('AJAX error:', { xhr: xhr, status: status, error: error }); - // Remove loading overlay - $loadingOverlay.remove(); - - // Show error message - $container.html('

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

'); - console.error('AJAX Error Response Text:', xhr.responseText); - } - }); - - } + // Theme handlers are initialized directly from the inline script + // We don't need a separate loadTheme function anymore // Initialize plugin action buttons function initPluginActions() { diff --git a/admin/settings.php b/admin/settings.php index 22c5dca..530ef3c 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -699,19 +699,42 @@ function wp_allstars_settings_page() { wp_enqueue_style('wp-allstars-admin', plugins_url('css/wp-allstars-admin.css', __FILE__)); wp_enqueue_style('wp-allstars-plugins', plugins_url('css/wp-allstars-plugins.css', __FILE__)); - // Add inline script to trigger theme loading through the main JS function + // Add inline script to load themes directly - same approach as plugins tab wp_add_inline_script('wp-allstars-admin', ' jQuery(document).ready(function($) { - console.log("Theme tab ready, checking if we need to load themes"); - // Use the main loadTheme function from wp-allstars-admin.js if available if ($("#wpa-theme-list").length && $("#wpa-theme-list").is(":empty")) { - console.log("Theme list is empty, calling loadTheme()"); - if (typeof window.loadTheme === "function") { - window.loadTheme(); - } else { - console.error("loadTheme function not found"); - $("#wpa-theme-list").html("

Error: Theme loading function not available.

"); - } + var $container = $("#wpa-theme-list"); + var $loadingOverlay = $("
"); + + // Show loading overlay + $container.css("position", "relative").append($loadingOverlay); + + // AJAX request to get themes + $.ajax({ + url: ajaxurl, + type: "POST", + data: { + action: "wp_allstars_get_themes", + _wpnonce: wpAllstars.nonce + }, + success: function(response) { + $loadingOverlay.remove(); + if (response.success) { + $container.html(response.data); + // Initialize theme action buttons + if (typeof initThemeHandlers === "function") { + initThemeHandlers(); + } + } else { + $container.html("

" + response.data + "

"); + } + }, + error: function(xhr, status, error) { + $loadingOverlay.remove(); + $container.html("

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

"); + console.error("AJAX Error:", xhr.responseText); + } + }); } }); ');