diff --git a/admin/js/wp-allstars-admin.js b/admin/js/wp-allstars-admin.js index bb341dc..a10ee38 100644 --- a/admin/js/wp-allstars-admin.js +++ b/admin/js/wp-allstars-admin.js @@ -64,40 +64,7 @@ jQuery(document).ready(function($) { e.stopPropagation(); }); - // Initialize tabs - $('.nav-tab-wrapper .nav-tab').on('click', function(e) { - e.preventDefault(); - var target = $(this).data('tab'); - - // Update active tab - $('.nav-tab-wrapper .nav-tab').removeClass('nav-tab-active'); - $(this).addClass('nav-tab-active'); - - // Show target tab content - $('.tab-content').hide(); - $('#' + target).show(); - - // Update URL hash - window.location.hash = target; - - // Load plugins if needed - if (target === 'recommended' && $('#wpa-plugin-list').length && $('#wpa-plugin-list').is(':empty')) { - loadPlugins('all'); - } - - // Load themes if needed - if (target === 'theme' && $('#wpa-theme-list').length && $('#wpa-theme-list').is(':empty')) { - loadTheme(); - } - }); - - // Initialize based on hash - if (window.location.hash) { - var hash = window.location.hash.substring(1); - $('.nav-tab-wrapper .nav-tab[data-tab="' + hash + '"]').trigger('click'); - } else { - $('.nav-tab-wrapper .nav-tab:first').trigger('click'); - } + // Remove JavaScript-based tab switching - let the native WordPress tab links work // Plugin category filters if ($('#wpa-plugin-filters').length) { @@ -115,7 +82,7 @@ jQuery(document).ready(function($) { // Load initial plugins if we're on the recommended tab if ($('#recommended').is(':visible') && $('#wpa-plugin-list').is(':empty')) { - loadPlugins('all'); + loadPlugins('minimal'); } } diff --git a/admin/settings.php b/admin/settings.php index b3fdf34..d41d493 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -617,6 +617,48 @@ function wp_allstars_settings_page() { add_thickbox(); 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 load plugins on page load + wp_add_inline_script('wp-allstars-admin', ' + jQuery(document).ready(function($) { + if ($("#wpa-plugin-list").length && $("#wpa-plugin-list").is(":empty")) { + var category = "' . esc_js($active_category) . '"; + var $container = $("#wpa-plugin-list"); + var $loadingOverlay = $("
"); + + // Show loading overlay + $container.css("position", "relative").append($loadingOverlay); + + // AJAX request to get plugins + $.ajax({ + url: ajaxurl, + type: "POST", + data: { + action: "wp_allstars_get_plugins", + category: category, + _wpnonce: wpAllstars.nonce + }, + success: function(response) { + $loadingOverlay.remove(); + if (response.success) { + $container.html(response.data); + // Initialize plugin action buttons + if (typeof initPluginActions === "function") { + initPluginActions(); + } + } else { + $container.html("

" + response.data + "

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

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

"); + console.error("AJAX Error:", xhr.responseText); + } + }); + } + }); + '); } elseif ($active_tab === 'theme') { wp_allstars_clear_theme_cache(); require_once ABSPATH . 'wp-admin/includes/theme.php'; @@ -625,6 +667,46 @@ function wp_allstars_settings_page() { add_thickbox(); 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 load theme on page load + wp_add_inline_script('wp-allstars-admin', ' + jQuery(document).ready(function($) { + if ($("#wpa-theme-list").length && $("#wpa-theme-list").is(":empty")) { + var $container = $("#wpa-theme-list"); + var $loadingOverlay = $("
"); + + // Show loading overlay + $container.css("position", "relative").append($loadingOverlay); + + // AJAX request to get theme + $.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 theme. Please try again. Error: " + error + "

"); + console.error("AJAX Error:", xhr.responseText); + } + }); + } + }); + '); } ?>
@@ -641,22 +723,22 @@ function wp_allstars_settings_page() {