array( 'antispam-bee', 'simple-cloudflare-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'; // Get our recommended plugins for this category $recommended_plugins = wpa_superstar_get_recommended_plugins(); if (!isset($recommended_plugins[$category])) { wp_send_json_error('Invalid category: ' . $category); } // Try to get cached data first $cached_data = wpa_superstar_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; } error_log('Fetching fresh data for category: ' . $category); error_log('Plugins to fetch: ' . implode(', ', $recommended_plugins[$category])); // 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 { error_log('Fetching plugin data for: ' . $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)) { 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()); continue; } } 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 wpa_superstar_set_cached_plugins($category, $res); // 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( 'screen' => 'plugin-install' )); // Set the items directly $wp_list_table->items = $plugins; $wp_list_table->set_pagination_args(array( 'total_items' => count($plugins), 'per_page' => count($plugins), )); 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_wpa_get_plugins', 'wpa_superstar_ajax_get_plugins'); // Remove the old plugins API filter since we're handling everything in the AJAX endpoint remove_filter('plugins_api_result', 'wpa_superstar_plugins_api_result'); // 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'); // Add transient caching for theme data function wpa_superstar_get_cached_theme() { $cache_key = 'wpa_superstar_theme_kadence'; return get_transient($cache_key); } function wpa_superstar_set_cached_theme($data) { $cache_key = 'wpa_superstar_theme_kadence'; set_transient($cache_key, $data, 12 * HOUR_IN_SECONDS); } // Add AJAX endpoint for theme function wpa_superstar_ajax_get_theme() { check_ajax_referer('updates'); if (!current_user_can('install_themes')) { wp_die(-1); } require_once ABSPATH . 'wp-admin/includes/theme.php'; // Try to get cached data first $cached_data = wpa_superstar_get_cached_theme(); if ($cached_data !== false) { error_log('Using cached theme data'); // Setup the list table with cached data $GLOBALS['tab'] = 'theme-install'; $_REQUEST['tab'] = 'theme-install'; $_REQUEST['type'] = 'theme-install'; set_current_screen('theme-install'); $wp_list_table = _get_list_table('WP_Theme_Install_List_Table', array( 'screen' => 'theme-install' )); // Override the items with our cached data $wp_list_table->items = array($cached_data); $wp_list_table->set_pagination_args(array( 'total_items' => 1, 'per_page' => 1, )); ob_start(); $wp_list_table->display(); $html = ob_get_clean(); wp_send_json_success($html); return; } error_log('Fetching fresh theme data for Kadence'); // If no cache, get fresh data try { $theme_data = themes_api('theme_information', array( 'slug' => 'kadence', 'fields' => array( 'sections' => false, 'rating' => true, 'ratings' => false, 'downloaded' => true, 'last_updated' => true, 'homepage' => true, 'description' => true, 'screenshot_url' => true, ) )); if (is_wp_error($theme_data)) { error_log('Error fetching theme data: ' . $theme_data->get_error_message()); wp_send_json_error('Failed to fetch theme data: ' . $theme_data->get_error_message()); return; } error_log('Successfully fetched theme data'); // Cache the results wpa_superstar_set_cached_theme($theme_data); // Setup the list table $GLOBALS['tab'] = 'theme-install'; $_REQUEST['tab'] = 'theme-install'; $_REQUEST['type'] = 'theme-install'; set_current_screen('theme-install'); $wp_list_table = _get_list_table('WP_Theme_Install_List_Table', array( 'screen' => 'theme-install' )); // Set the items directly $wp_list_table->items = array($theme_data); $wp_list_table->set_pagination_args(array( 'total_items' => 1, 'per_page' => 1, )); ob_start(); $wp_list_table->display(); $html = ob_get_clean(); wp_send_json_success($html); } catch (Exception $e) { error_log('Failed to fetch theme data: ' . $e->getMessage()); wp_send_json_error('Failed to fetch theme data: ' . $e->getMessage()); } } add_action('wp_ajax_wpa_get_theme', 'wpa_superstar_ajax_get_theme'); // Clear theme cache when themes are updated function wpa_superstar_clear_theme_cache() { delete_transient('wpa_superstar_theme_kadence'); } add_action('upgrader_process_complete', 'wpa_superstar_clear_theme_cache', 10, 0); add_action('switch_theme', 'wpa_superstar_clear_theme_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'; // Clear cache and load required files if ($active_tab === 'recommended') { wpa_superstar_clear_plugin_cache(); require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; wp_enqueue_script('plugin-install'); wp_enqueue_script('updates'); add_thickbox(); } elseif ($active_tab === 'theme') { wpa_superstar_clear_theme_cache(); require_once ABSPATH . 'wp-admin/includes/theme.php'; wp_enqueue_script('theme-install'); wp_enqueue_script('updates'); add_thickbox(); } ?>

Version