Fix plugin browser freezing and add loading state: - Optimize plugin API filtering - Add individual plugin fetching - Add loading overlay with spinner - Improve error handling

This commit is contained in:
Marcus Quinn
2025-03-14 03:38:54 +00:00
parent 1d70eb4c33
commit 20bfd2b976
2 changed files with 87 additions and 21 deletions

View File

@ -194,3 +194,22 @@
margin-top: 20px; margin-top: 20px;
padding: 0; padding: 0;
} }
/* Loading overlay */
.wpa-loading-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(255, 255, 255, 0.8);
z-index: 100;
display: flex;
align-items: center;
justify-content: center;
}
.wp-list-table-container {
position: relative;
min-height: 200px;
}

View File

@ -65,37 +65,72 @@ function wpa_superstar_get_recommended_plugins() {
// Filter plugins API to show only our recommended plugins // Filter plugins API to show only our recommended plugins
function wpa_superstar_plugins_api_result($res, $action, $args) { function wpa_superstar_plugins_api_result($res, $action, $args) {
if ($action !== 'query_plugins') { // Only filter if we're on our plugin page and it's a plugin query
if (!is_admin() ||
empty($_GET['page']) ||
$_GET['page'] !== 'wpa-superstar' ||
$action !== 'query_plugins') {
return $res; return $res;
} }
if (!empty($_GET['page']) && $_GET['page'] === 'wpa-superstar') { // Get the current category
$category = isset($_GET['category']) ? sanitize_key($_GET['category']) : 'minimal'; $category = isset($_GET['category']) ? sanitize_key($_GET['category']) : 'minimal';
$recommended_plugins = wpa_superstar_get_recommended_plugins(); $recommended_plugins = wpa_superstar_get_recommended_plugins();
if (isset($recommended_plugins[$category])) { // Check if category exists and has plugins
// Get plugin data for our recommended plugins if (!isset($recommended_plugins[$category]) || empty($recommended_plugins[$category])) {
$args = (object) array( return $res;
'per_page' => 100, }
try {
// Get plugin data for each slug individually to prevent timeouts
$plugins = array();
foreach ($recommended_plugins[$category] as $slug) {
$plugin_data = plugins_api('plugin_information', array(
'slug' => $slug,
'fields' => array( 'fields' => array(
'last_updated' => true, 'short_description' => true,
'active_installs' => true, 'sections' => false,
'requires' => true,
'rating' => true,
'ratings' => false,
'downloaded' => true, 'downloaded' => true,
'last_updated' => true,
'added' => false,
'tags' => false,
'compatibility' => false,
'homepage' => true,
'versions' => false,
'donate_link' => false,
'reviews' => false,
'banners' => false,
'icons' => true, 'icons' => true,
'active_installs' => true,
'group' => false,
'contributors' => false,
)
));
if (!is_wp_error($plugin_data)) {
$plugins[] = $plugin_data;
}
}
// Create a valid response object
$res = (object) array(
'info' => array(
'page' => 1,
'pages' => 1,
'results' => count($plugins),
), ),
'locale' => get_user_locale(), 'plugins' => $plugins
'slugs' => $recommended_plugins[$category]
); );
$query = plugins_api('query_plugins', $args);
if (!is_wp_error($query)) {
return $query;
}
}
}
return $res; return $res;
} catch (Exception $e) {
// If something goes wrong, return original results
return $res;
}
} }
add_filter('plugins_api_result', 'wpa_superstar_plugins_api_result', 10, 3); add_filter('plugins_api_result', 'wpa_superstar_plugins_api_result', 10, 3);
@ -162,6 +197,9 @@ function wpa_superstar_settings_page() {
</div> </div>
<div class="wp-list-table-container"> <div class="wp-list-table-container">
<div class="wpa-loading-overlay" style="display: none;">
<span class="spinner is-active"></span>
</div>
<?php <?php
$wp_list_table = _get_list_table('WP_Plugin_Install_List_Table'); $wp_list_table = _get_list_table('WP_Plugin_Install_List_Table');
$wp_list_table->prepare_items(); $wp_list_table->prepare_items();
@ -169,6 +207,15 @@ function wpa_superstar_settings_page() {
?> ?>
</div> </div>
<script>
jQuery(document).ready(function($) {
// Show loading state when changing categories
$('.wpa-plugin-filters a').on('click', function() {
$('.wpa-loading-overlay').show();
});
});
</script>
<?php elseif ($active_tab == 'general'): ?> <?php elseif ($active_tab == 'general'): ?>
<div class="wpa-superstar-toggle"> <div class="wpa-superstar-toggle">
<label for="wpa_superstar_lazy_load"> <label for="wpa_superstar_lazy_load">