Fix plugin filtering to match defined lists: - Ensure only recommended plugins are displayed - Add better error handling - Fix table initialization - Improve API error handling

This commit is contained in:
Marcus Quinn
2025-03-14 04:08:11 +00:00
parent 8ecfc06661
commit b0d49028e3

View File

@ -104,6 +104,7 @@ function wpa_superstar_ajax_get_plugins() {
// Setup the list table with cached data // Setup the list table with cached data
$GLOBALS['tab'] = 'plugin-install'; $GLOBALS['tab'] = 'plugin-install';
$_REQUEST['tab'] = 'plugin-install'; $_REQUEST['tab'] = 'plugin-install';
$_REQUEST['type'] = 'plugin-install';
set_current_screen('plugin-install'); set_current_screen('plugin-install');
$wp_list_table = _get_list_table('WP_Plugin_Install_List_Table', array( $wp_list_table = _get_list_table('WP_Plugin_Install_List_Table', array(
@ -128,34 +129,41 @@ function wpa_superstar_ajax_get_plugins() {
// If no cache, get fresh data // If no cache, get fresh data
try { try {
$plugins = array(); $plugins = array();
// Only fetch plugins that are in our recommended list for this category
foreach ($recommended_plugins[$category] as $slug) { foreach ($recommended_plugins[$category] as $slug) {
$plugin_data = plugins_api('plugin_information', array( try {
'slug' => $slug, $plugin_data = plugins_api('plugin_information', array(
'fields' => array( 'slug' => $slug,
'short_description' => true, 'fields' => array(
'sections' => false, 'short_description' => true,
'requires' => true, 'sections' => false,
'rating' => true, 'requires' => true,
'ratings' => false, 'rating' => true,
'downloaded' => true, 'ratings' => false,
'last_updated' => true, 'downloaded' => true,
'added' => false, 'last_updated' => true,
'tags' => false, 'added' => false,
'compatibility' => false, 'tags' => false,
'homepage' => true, 'compatibility' => false,
'versions' => false, 'homepage' => true,
'donate_link' => false, 'versions' => false,
'reviews' => false, 'donate_link' => false,
'banners' => false, 'reviews' => false,
'icons' => true, 'banners' => false,
'active_installs' => true, 'icons' => true,
'group' => false, 'active_installs' => true,
'contributors' => false, 'group' => false,
) 'contributors' => false,
)); )
));
if (!is_wp_error($plugin_data)) {
$plugins[] = $plugin_data; if (!is_wp_error($plugin_data)) {
$plugins[] = $plugin_data;
}
} catch (Exception $e) {
// Skip this plugin if there's an error
continue;
} }
} }
@ -175,6 +183,7 @@ function wpa_superstar_ajax_get_plugins() {
// Setup the list table // Setup the list table
$GLOBALS['tab'] = 'plugin-install'; $GLOBALS['tab'] = 'plugin-install';
$_REQUEST['tab'] = 'plugin-install'; $_REQUEST['tab'] = 'plugin-install';
$_REQUEST['type'] = 'plugin-install';
set_current_screen('plugin-install'); set_current_screen('plugin-install');
$wp_list_table = _get_list_table('WP_Plugin_Install_List_Table', array( $wp_list_table = _get_list_table('WP_Plugin_Install_List_Table', array(
@ -195,7 +204,7 @@ function wpa_superstar_ajax_get_plugins() {
wp_send_json_success($html); wp_send_json_success($html);
} catch (Exception $e) { } catch (Exception $e) {
wp_send_json_error('Failed to fetch plugin data'); wp_send_json_error('Failed to fetch plugin data: ' . $e->getMessage());
} }
} }
add_action('wp_ajax_wpa_get_plugins', 'wpa_superstar_ajax_get_plugins'); add_action('wp_ajax_wpa_get_plugins', 'wpa_superstar_ajax_get_plugins');