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
$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(
@ -128,7 +129,10 @@ function wpa_superstar_ajax_get_plugins() {
// 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) {
try {
$plugin_data = plugins_api('plugin_information', array(
'slug' => $slug,
'fields' => array(
@ -157,6 +161,10 @@ function wpa_superstar_ajax_get_plugins() {
if (!is_wp_error($plugin_data)) {
$plugins[] = $plugin_data;
}
} catch (Exception $e) {
// Skip this plugin if there's an error
continue;
}
}
// Create response object
@ -175,6 +183,7 @@ function wpa_superstar_ajax_get_plugins() {
// Setup the list table
$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(
@ -195,7 +204,7 @@ function wpa_superstar_ajax_get_plugins() {
wp_send_json_success($html);
} 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');