Make Free Plugins filter menu dynamically generated from data file

This commit is contained in:
Marcus Quinn
2025-03-24 20:40:52 +00:00
parent 4d671d5901
commit 673d4a60fd

View File

@ -43,61 +43,54 @@ class WP_Allstars_Free_Plugins_Manager {
public static function display_tab_content() { public static function display_tab_content() {
// Get the active category from query params or use default // Get the active category from query params or use default
$active_category = isset($_GET['category']) ? sanitize_text_field($_GET['category']) : 'minimal'; $active_category = isset($_GET['category']) ? sanitize_text_field($_GET['category']) : 'minimal';
// Get all available plugin categories from the data file
$plugin_categories = wp_allstars_get_free_plugins();
// Define priority categories to display first
$priority_categories = array('minimal', 'admin');
// Start HTML output
?> ?>
<div class="wp-allstars-settings-content tab-content" id="recommended"> <div class="wp-allstars-settings-content tab-content" id="recommended">
<div id="wpa-plugin-filters" class="wp-filter"> <div id="wpa-plugin-filters" class="wp-filter">
<ul class="filter-links"> <ul class="filter-links">
<li><a href="#" data-category="minimal" class="<?php echo $active_category == 'minimal' ? 'current' : ''; ?>"> <?php
<?php esc_html_e('Minimal', 'wp-allstars'); ?> // First output priority categories
foreach ($priority_categories as $category) {
if (isset($plugin_categories[$category])) {
$category_name = ucfirst($category);
if ($category == 'cms') $category_name = 'CMS';
if ($category == 'crm') $category_name = 'CRM';
if ($category == 'ecommerce') $category_name = 'eCommerce';
if ($category == 'lms') $category_name = 'LMS';
if ($category == 'seo') $category_name = 'SEO';
?>
<li><a href="#" data-category="<?php echo esc_attr($category); ?>" class="<?php echo $active_category == $category ? 'current' : ''; ?>">
<?php echo esc_html($category_name); ?>
</a></li> </a></li>
<li><a href="#" data-category="admin" class="<?php echo $active_category == 'admin' ? 'current' : ''; ?>"> <?php
<?php esc_html_e('Admin', 'wp-allstars'); ?> }
</a></li> }
<li><a href="#" data-category="affiliates" class="<?php echo $active_category == 'affiliates' ? 'current' : ''; ?>">
<?php esc_html_e('Affiliates', 'wp-allstars'); ?> // Then output all other categories alphabetically
</a></li> $remaining_categories = array_diff(array_keys($plugin_categories), $priority_categories);
<li><a href="#" data-category="ai" class="<?php echo $active_category == 'ai' ? 'current' : ''; ?>"> sort($remaining_categories);
<?php esc_html_e('AI', 'wp-allstars'); ?>
</a></li> foreach ($remaining_categories as $category) {
<li><a href="#" data-category="cms" class="<?php echo $active_category == 'cms' ? 'current' : ''; ?>"> $category_name = ucfirst($category);
<?php esc_html_e('CMS', 'wp-allstars'); ?> if ($category == 'cms') $category_name = 'CMS';
</a></li> if ($category == 'crm') $category_name = 'CRM';
<li><a href="#" data-category="compliance" class="<?php echo $active_category == 'compliance' ? 'current' : ''; ?>"> if ($category == 'ecommerce') $category_name = 'eCommerce';
<?php esc_html_e('Compliance', 'wp-allstars'); ?> if ($category == 'lms') $category_name = 'LMS';
</a></li> if ($category == 'seo') $category_name = 'SEO';
<li><a href="#" data-category="crm" class="<?php echo $active_category == 'crm' ? 'current' : ''; ?>"> ?>
<?php esc_html_e('CRM', 'wp-allstars'); ?> <li><a href="#" data-category="<?php echo esc_attr($category); ?>" class="<?php echo $active_category == $category ? 'current' : ''; ?>">
</a></li> <?php echo esc_html($category_name); ?>
<li><a href="#" data-category="ecommerce" class="<?php echo $active_category == 'ecommerce' ? 'current' : ''; ?>">
<?php esc_html_e('eCommerce', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="lms" class="<?php echo $active_category == 'lms' ? 'current' : ''; ?>">
<?php esc_html_e('LMS', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="media" class="<?php echo $active_category == 'media' ? 'current' : ''; ?>">
<?php esc_html_e('Media', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="seo" class="<?php echo $active_category == 'seo' ? 'current' : ''; ?>">
<?php esc_html_e('SEO', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="setup" class="<?php echo $active_category == 'setup' ? 'current' : ''; ?>">
<?php esc_html_e('Setup', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="social" class="<?php echo $active_category == 'social' ? 'current' : ''; ?>">
<?php esc_html_e('Social', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="speed" class="<?php echo $active_category == 'speed' ? 'current' : ''; ?>">
<?php esc_html_e('Speed', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="translation" class="<?php echo $active_category == 'translation' ? 'current' : ''; ?>">
<?php esc_html_e('Translation', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="advanced" class="<?php echo $active_category == 'advanced' ? 'current' : ''; ?>">
<?php esc_html_e('Advanced', 'wp-allstars'); ?>
</a></li>
<li><a href="#" data-category="debug" class="<?php echo $active_category == 'debug' ? 'current' : ''; ?>">
<?php esc_html_e('Debug', 'wp-allstars'); ?>
</a></li> </a></li>
<?php
}
?>
</ul> </ul>
</div> </div>