plugins); wp_send_json_success($html); 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('Plugins to fetch: ' . implode(', ', $recommended_plugins[$category])); 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; } } if (empty($plugins)) { wp_send_json_error('No plugin data could be retrieved for category: ' . $category); return; } 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 self::set_cached_plugins($category, $res); // Generate plugin cards HTML $html = self::generate_plugin_cards($plugins); 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()); } } /** * Generate HTML for plugin cards * * @param array $plugins Array of plugin data * @return string HTML for the plugin cards */ public static function generate_plugin_cards($plugins) { if (empty($plugins)) { return '

No plugins found.

'; } ob_start(); ?>

name); ?>

short_description); ?>

author); ?>

$plugin->rating, 'type' => 'percent', 'number' => $plugin->num_ratings)); ?>
last_updated))); ?>
active_installs >= 1000000) { $active_installs_millions = floor($plugin->active_installs / 1000000); $active_installs_text = sprintf( _n('%s+ Million Active Installations', '%s+ Million Active Installations', $active_installs_millions), number_format_i18n($active_installs_millions) ); } elseif (0 == $plugin->active_installs) { $active_installs_text = _x('Less Than 10 Active Installations', 'Active plugin installations'); } else { $active_installs_text = sprintf( _n('%s+ Active Installation', '%s+ Active Installations', $plugin->active_installs), number_format_i18n($plugin->active_installs) ); } /* translators: %s: number of active installations */ echo esc_html($active_installs_text); ?>
tested) && version_compare($version, $plugin->tested, '>')) { echo '' . __('Untested with your version of WordPress') . ''; } elseif (!empty($plugin->requires) && version_compare($version, $plugin->requires, '<')) { echo '' . __('Incompatible with your version of WordPress') . ''; } else { echo '' . __('Compatible with your version of WordPress') . ''; } ?>
slug])) { $pro_plugin = $pro_plugins[$plugin->slug]; $pro_url = self::get_pro_plugin_url($pro_plugin); if (!empty($pro_url)) { echo '
  • ' . esc_html__('PRO', 'wp-allstars') . '
  • '; } } } /** * Get the URL for a pro plugin from its config * * @param array $pro_plugin The pro plugin configuration array * @return string The URL for the pro plugin */ public static function get_pro_plugin_url($pro_plugin) { // First check if there's a button_group defined if (isset($pro_plugin['button_group']) && is_array($pro_plugin['button_group'])) { foreach ($pro_plugin['button_group'] as $button) { // Return the URL for the primary button if available if (isset($button['primary']) && $button['primary'] && !empty($button['url'])) { return $button['url']; } } // If no primary button found, return the first button URL if (!empty($pro_plugin['button_group'][0]['url'])) { return $pro_plugin['button_group'][0]['url']; } } // Fall back to the main URL if available if (!empty($pro_plugin['url'])) { return $pro_plugin['url']; } return ''; } /** * Clear plugin cache when plugins are updated, activated, or deactivated */ public static function clear_plugin_cache() { $recommended_plugins = wp_allstars_get_recommended_plugins(); foreach (array_keys($recommended_plugins) as $category) { delete_transient('wp_allstars_plugins_' . $category); } } } // Initialize the class WP_Allstars_Plugin_Manager::init();