Making WordPress.org


Ignore:
Timestamp:
05/13/2024 02:05:49 AM (2 years ago)
Author:
dufresnesteven
Message:

wporg-plugins-2024: Turn on experimental directory filters for non-search views behind "show_filters" query var.
Note: Filters are not complete. Use at your own risk :).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/inc/block-config.php

    r13451 r13692  
    99add_filter( 'wporg_query_filter_options_sort', __NAMESPACE__ . '\wporg_query_filter_options_sort' );
    1010add_filter( 'wporg_query_filter_options_business_model', __NAMESPACE__ . '\wporg_query_filter_options_business_model' );
     11add_filter( 'wporg_query_filter_options_plugin_category', __NAMESPACE__ . '\wporg_query_filter_options_plugin_category' );
    1112add_filter( 'wporg_query_filter_in_form', __NAMESPACE__ . '\wporg_query_filter_in_form' );
    1213add_filter( 'wporg_query_total_label', __NAMESPACE__ . '\wporg_query_total_label', 10, 2 );
     
    129130function wporg_query_filter_options_business_model() {
    130131    $options = array(
     132        'all'        => __( 'All', 'wporg-plugins' ),
    131133        'commercial' => __( 'Commercial', 'wporg-plugins' ),
    132         'community' => __( 'Community', 'wporg-plugins' ),
     134        'community'  => __( 'Community', 'wporg-plugins' ),
    133135    );
    134136    $label = __( 'Type', 'wporg-plugins' );
     
    144146        'options'  => $options ,
    145147        'selected' => [ get_query_var( 'plugin_business_model' ) ],
     148    );
     149}
     150
     151function wporg_query_filter_options_plugin_category() {
     152    $options = [];
     153
     154    foreach ( get_terms( 'plugin_category', [ 'hide_empty' => true ] ) as $term ) {
     155        $options[ $term->slug ] = $term->name;
     156    }
     157   
     158    $count = count( (array) get_query_var( 'plugin_category' ) );
     159    $label = sprintf(
     160        /* translators: The dropdown label for filtering, %s is the selected term count. */
     161        _n( 'Categories <span>%s</span>', 'Categories <span>%s</span>', number_format_i18n( $count ), 'wporg-plugins' ),
     162        $count
     163    );
     164   
     165    return array(
     166        'label'    => $label,
     167        'title'    => __( 'Category', 'wporg-plugins' ),
     168        'key'      => 'plugin_category',
     169        'action'   => '',
     170        'options'  => $options,
     171        'selected' => (array) get_query_var( 'plugin_category' ),
    146172    );
    147173}
     
    186212    }
    187213
     214    // Temporary for feature flag
     215    if ( isset( $_GET['show_filters'] )  ) {
     216        echo '<input type="hidden" name="show_filters" value="1" />';
     217    }
     218
    188219}
    189220
Note: See TracChangeset for help on using the changeset viewer.