Fix plugin list display and improve error handling
This commit is contained in:
@ -205,12 +205,14 @@ function wp_allstars_ajax_get_plugins() {
|
|||||||
$recommended_plugins = wp_allstars_get_recommended_plugins();
|
$recommended_plugins = wp_allstars_get_recommended_plugins();
|
||||||
if (!isset($recommended_plugins[$category])) {
|
if (!isset($recommended_plugins[$category])) {
|
||||||
wp_send_json_error('Invalid category: ' . $category);
|
wp_send_json_error('Invalid category: ' . $category);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get cached data first
|
// Try to get cached data first
|
||||||
$cached_data = wp_allstars_get_cached_plugins($category);
|
$cached_data = wp_allstars_get_cached_plugins($category);
|
||||||
if ($cached_data !== false) {
|
if ($cached_data !== false) {
|
||||||
error_log('Using cached data for category: ' . $category);
|
error_log('Using cached data for category: ' . $category);
|
||||||
|
try {
|
||||||
// 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';
|
||||||
@ -228,24 +230,7 @@ function wp_allstars_ajax_get_plugins() {
|
|||||||
'per_page' => count($cached_data->plugins),
|
'per_page' => count($cached_data->plugins),
|
||||||
));
|
));
|
||||||
|
|
||||||
add_filter('plugin_install_action_links', function($action_links, $plugin) {
|
add_filter('plugin_install_action_links', 'wp_allstars_add_pro_button', 10, 2);
|
||||||
// Get pro plugins configuration
|
|
||||||
$pro_plugins = wp_allstars_get_pro_plugins_config();
|
|
||||||
|
|
||||||
// Check if this plugin has a pro version
|
|
||||||
foreach ($pro_plugins as $pro_plugin) {
|
|
||||||
if (isset($pro_plugin['free_slug']) && $pro_plugin['free_slug'] === $plugin['slug']) {
|
|
||||||
$action_links[] = sprintf(
|
|
||||||
'<a class="button button-primary" href="%s" target="_blank">%s</a>',
|
|
||||||
esc_url($pro_plugin['url']),
|
|
||||||
esc_html__('Go Pro', 'wp-allstars')
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $action_links;
|
|
||||||
}, 10, 2);
|
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$wp_list_table->display();
|
$wp_list_table->display();
|
||||||
@ -253,12 +238,15 @@ function wp_allstars_ajax_get_plugins() {
|
|||||||
|
|
||||||
wp_send_json_success($html);
|
wp_send_json_success($html);
|
||||||
return;
|
return;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log('Error displaying cached plugins: ' . $e->getMessage());
|
||||||
|
// Fall through to fetch fresh data
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log('Fetching fresh data for category: ' . $category);
|
error_log('Fetching fresh data for category: ' . $category);
|
||||||
error_log('Plugins to fetch: ' . implode(', ', $recommended_plugins[$category]));
|
error_log('Plugins to fetch: ' . implode(', ', $recommended_plugins[$category]));
|
||||||
|
|
||||||
// If no cache, get fresh data
|
|
||||||
try {
|
try {
|
||||||
$plugins = array();
|
$plugins = array();
|
||||||
|
|
||||||
@ -303,6 +291,11 @@ function wp_allstars_ajax_get_plugins() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($plugins)) {
|
||||||
|
wp_send_json_error('No plugin data could be retrieved for category: ' . $category);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
error_log('Total plugins fetched: ' . count($plugins));
|
error_log('Total plugins fetched: ' . count($plugins));
|
||||||
|
|
||||||
// Create response object
|
// Create response object
|
||||||
@ -335,7 +328,28 @@ function wp_allstars_ajax_get_plugins() {
|
|||||||
'per_page' => count($plugins),
|
'per_page' => count($plugins),
|
||||||
));
|
));
|
||||||
|
|
||||||
add_filter('plugin_install_action_links', function($action_links, $plugin) {
|
add_filter('plugin_install_action_links', 'wp_allstars_add_pro_button', 10, 2);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$wp_list_table->display();
|
||||||
|
$html = ob_get_clean();
|
||||||
|
|
||||||
|
if (empty($html)) {
|
||||||
|
wp_send_json_error('Failed to generate plugin display HTML');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_send_json_success($html);
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log('Failed to fetch plugin data: ' . $e->getMessage());
|
||||||
|
wp_send_json_error('Failed to fetch plugin data: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('wp_ajax_wp_allstars_get_plugins', 'wp_allstars_ajax_get_plugins');
|
||||||
|
|
||||||
|
// Helper function to add pro button to plugin cards
|
||||||
|
function wp_allstars_add_pro_button($action_links, $plugin) {
|
||||||
// Get pro plugins configuration
|
// Get pro plugins configuration
|
||||||
$pro_plugins = wp_allstars_get_pro_plugins_config();
|
$pro_plugins = wp_allstars_get_pro_plugins_config();
|
||||||
|
|
||||||
@ -352,20 +366,7 @@ function wp_allstars_ajax_get_plugins() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $action_links;
|
return $action_links;
|
||||||
}, 10, 2);
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
$wp_list_table->display();
|
|
||||||
$html = ob_get_clean();
|
|
||||||
|
|
||||||
wp_send_json_success($html);
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
error_log('Failed to fetch plugin data: ' . $e->getMessage());
|
|
||||||
wp_send_json_error('Failed to fetch plugin data: ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
add_action('wp_ajax_wp_allstars_get_plugins', 'wp_allstars_ajax_get_plugins');
|
|
||||||
|
|
||||||
// Remove the old plugins API filter since we're handling everything in the AJAX endpoint
|
// Remove the old plugins API filter since we're handling everything in the AJAX endpoint
|
||||||
remove_filter('plugins_api_result', 'wp_allstars_plugins_api_result');
|
remove_filter('plugins_api_result', 'wp_allstars_plugins_api_result');
|
||||||
|
@ -31,8 +31,9 @@ register_activation_hook( __FILE__, 'wp_allstars_activate' );
|
|||||||
// Load core functionality
|
// Load core functionality
|
||||||
require_once plugin_dir_path(__FILE__) . 'includes/class-wp-allstars-auto-upload.php';
|
require_once plugin_dir_path(__FILE__) . 'includes/class-wp-allstars-auto-upload.php';
|
||||||
|
|
||||||
// Load admin UI
|
// Load admin UI and configurations
|
||||||
if ( is_admin() ) {
|
if ( is_admin() ) {
|
||||||
|
require_once plugin_dir_path( __FILE__ ) . 'admin/pro-plugins-config.php';
|
||||||
require_once plugin_dir_path( __FILE__ ) . 'admin/settings.php';
|
require_once plugin_dir_path( __FILE__ ) . 'admin/settings.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user