array( 'antispam-bee', 'turnstile' ), 'advanced' => array( 'advanced-custom-fields', 'admin-menu-editor', 'burst-statistics', 'freesoul-deactivate-plugins', 'plugin-toggle', 'pretty-links', 'seo-by-rank-math', 'fluent-crm', 'fluentform', 'fluent-smtp', 'fluent-support' ), 'ecommerce' => array( 'woocommerce', 'client-booking' ), 'lms' => array( 'tutor' ) ); } // Add transient caching for plugin data function wpa_superstar_get_cached_plugins($category) { $cache_key = 'wpa_superstar_plugins_' . $category; $cached_data = get_transient($cache_key); if ($cached_data !== false) { return $cached_data; } return false; } function wpa_superstar_set_cached_plugins($category, $data) { $cache_key = 'wpa_superstar_plugins_' . $category; set_transient($cache_key, $data, 12 * HOUR_IN_SECONDS); } // Add AJAX endpoint for plugin list function wpa_superstar_ajax_get_plugins() { check_ajax_referer('updates'); if (!current_user_can('install_plugins')) { wp_die(-1); } $category = isset($_GET['category']) ? sanitize_key($_GET['category']) : 'minimal'; require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Set up the query args to match our filter $_GET['page'] = 'wpa-superstar'; // Set this so our filter knows to run $_REQUEST['page'] = 'wpa-superstar'; // Setup the list table $wp_list_table = _get_list_table('WP_Plugin_Install_List_Table', array( 'screen' => 'plugin-install', )); // Force per_page to match our category size $recommended_plugins = wpa_superstar_get_recommended_plugins(); $per_page = isset($recommended_plugins[$category]) ? count($recommended_plugins[$category]) : 10; // Set up the query args set_current_screen('plugin-install'); $_REQUEST['type'] = 'search'; $_REQUEST['s'] = ''; // Empty search to get all plugins $_REQUEST['tab'] = 'search'; $_REQUEST['per_page'] = $per_page; $wp_list_table->prepare_items(); ob_start(); $wp_list_table->display(); $html = ob_get_clean(); wp_send_json_success($html); } add_action('wp_ajax_wpa_get_plugins', 'wpa_superstar_ajax_get_plugins'); // Filter plugins API to show only our recommended plugins function wpa_superstar_plugins_api_result($res, $action, $args) { // Only filter if we're on our plugin page and it's a plugin query if (!is_admin() || empty($_REQUEST['page']) || $_REQUEST['page'] !== 'wpa-superstar' || $action !== 'query_plugins') { return $res; } // Get the current category $category = isset($_GET['category']) ? sanitize_key($_GET['category']) : 'minimal'; // Try to get cached data first $cached_data = wpa_superstar_get_cached_plugins($category); if ($cached_data !== false) { return $cached_data; } $recommended_plugins = wpa_superstar_get_recommended_plugins(); // Check if category exists and has plugins if (!isset($recommended_plugins[$category]) || empty($recommended_plugins[$category])) { return $res; } 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( 'short_description' => true, 'sections' => false, 'requires' => true, 'rating' => true, 'ratings' => false, 'downloaded' => true, 'last_updated' => true, 'added' => false, 'tags' => false, 'compatibility' => false, 'homepage' => true, 'versions' => false, 'donate_link' => false, 'reviews' => false, 'banners' => false, '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), ), 'plugins' => $plugins ); // Cache the results wpa_superstar_set_cached_plugins($category, $res); return $res; } catch (Exception $e) { return $res; } } add_filter('plugins_api_result', 'wpa_superstar_plugins_api_result', 10, 3); // Clear plugin cache when plugins are updated, activated, or deactivated function wpa_superstar_clear_plugin_cache() { $recommended_plugins = wpa_superstar_get_recommended_plugins(); foreach (array_keys($recommended_plugins) as $category) { delete_transient('wpa_superstar_plugins_' . $category); } } add_action('upgrader_process_complete', 'wpa_superstar_clear_plugin_cache', 10, 0); add_action('activated_plugin', 'wpa_superstar_clear_plugin_cache'); add_action('deactivated_plugin', 'wpa_superstar_clear_plugin_cache'); add_action('deleted_plugin', 'wpa_superstar_clear_plugin_cache'); add_action('update_option_active_plugins', 'wpa_superstar_clear_plugin_cache'); // Settings page HTML function wpa_superstar_settings_page() { global $tabs; $active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'general'; $active_category = isset($_GET['category']) ? $_GET['category'] : 'minimal'; // Ensure required files are loaded if ($active_tab === 'recommended') { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; wp_enqueue_script('plugin-install'); wp_enqueue_script('updates'); add_thickbox(); } ?>