From 90ea4e7dbc66d93f2bde20dda42239ca4662d588 Mon Sep 17 00:00:00 2001 From: Marcus Quinn Date: Sat, 15 Mar 2025 15:29:29 +0000 Subject: [PATCH] Implement progressive loading for plugins with animations and batch loading --- admin/settings.php | 178 ++++++++++++++++++++++----------------------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/admin/settings.php b/admin/settings.php index 1abc333..d5c9472 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -102,7 +102,6 @@ function wp_allstars_get_recommended_plugins() { 'post-meta-data-manager', 'post-type-switcher', 'pretty-link', - 'query-monitor', 'seo-by-rank-math', 'really-simple-ssl', 'remove-cpt-base', @@ -141,6 +140,7 @@ function wp_allstars_get_recommended_plugins() { 'debug' => array( 'debug-log-manager', 'gotmls', + 'query-monitor', 'string-locator', 'user-switching', 'wp-crontrol' @@ -174,6 +174,8 @@ function wp_allstars_ajax_get_plugins() { } $category = isset($_GET['category']) ? sanitize_key($_GET['category']) : 'minimal'; + $batch_size = isset($_GET['batch_size']) ? intval($_GET['batch_size']) : 5; + $offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0; require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; @@ -183,46 +185,17 @@ function wp_allstars_ajax_get_plugins() { wp_send_json_error('Invalid category: ' . $category); } - // Try to get cached data first - $cached_data = wp_allstars_get_cached_plugins($category); - if ($cached_data !== false) { - error_log('Using cached data for category: ' . $category); - // Setup the list table with cached data - $GLOBALS['tab'] = 'plugin-install'; - $_REQUEST['tab'] = 'plugin-install'; - $_REQUEST['type'] = 'plugin-install'; - set_current_screen('plugin-install'); - - $wp_list_table = _get_list_table('WP_Plugin_Install_List_Table', array( - 'screen' => 'plugin-install' - )); - - // Override the items with our cached data - $wp_list_table->items = $cached_data->plugins; - $wp_list_table->set_pagination_args(array( - 'total_items' => count($cached_data->plugins), - 'per_page' => count($cached_data->plugins), - )); - - ob_start(); - $wp_list_table->display(); - $html = ob_get_clean(); - - wp_send_json_success($html); - return; - } + // Get the total number of plugins for this category + $total_plugins = count($recommended_plugins[$category]); - error_log('Fetching fresh data for category: ' . $category); - error_log('Plugins to fetch: ' . implode(', ', $recommended_plugins[$category])); + // Get the current batch of plugins + $current_batch = array_slice($recommended_plugins[$category], $offset, $batch_size); - // If no cache, get fresh data try { $plugins = array(); - // Only fetch plugins that are in our recommended list for this category - foreach ($recommended_plugins[$category] as $slug) { + foreach ($current_batch as $slug) { try { - error_log('Fetching plugin data for: ' . $slug); $plugin_data = plugins_api('plugin_information', array( 'slug' => $slug, 'fields' => array( @@ -252,7 +225,6 @@ function wp_allstars_ajax_get_plugins() { error_log('Error fetching plugin data for ' . $slug . ': ' . $plugin_data->get_error_message()); } else { $plugins[] = $plugin_data; - error_log('Successfully fetched data for: ' . $slug); } } catch (Exception $e) { error_log('Exception fetching plugin data for ' . $slug . ': ' . $e->getMessage()); @@ -260,21 +232,6 @@ function wp_allstars_ajax_get_plugins() { } } - error_log('Total plugins fetched: ' . count($plugins)); - - // Create response object - $res = (object) array( - 'info' => array( - 'page' => 1, - 'pages' => 1, - 'results' => count($plugins), - ), - 'plugins' => $plugins - ); - - // Cache the results - wp_allstars_set_cached_plugins($category, $res); - // Setup the list table $GLOBALS['tab'] = 'plugin-install'; $_REQUEST['tab'] = 'plugin-install'; @@ -296,7 +253,12 @@ function wp_allstars_ajax_get_plugins() { $wp_list_table->display(); $html = ob_get_clean(); - wp_send_json_success($html); + wp_send_json_success(array( + 'html' => $html, + 'total' => $total_plugins, + 'remaining' => $total_plugins - ($offset + count($plugins)), + 'offset' => $offset + count($plugins) + )); } catch (Exception $e) { error_log('Failed to fetch plugin data: ' . $e->getMessage()); @@ -860,21 +822,50 @@ function wp_allstars_settings_page() {
-
- -
+
+ +