Making WordPress.org

Changeset 3343


Ignore:
Timestamp:
06/13/2016 06:18:01 PM (9 years ago)
Author:
obenland
Message:

Plugin Directory: Allow users to browse their favorite plugins.

See #1573.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3342 r3343  
    427427                    $wp_query->query_vars['p'] = -1;
    428428                }
     429
     430                add_filter( 'posts_where', array( $this, 'pre_get_posts_sql_browse' ) );
    429431                break;
    430432
    431433            case 'popular':
    432                 add_filter( 'posts_where', array( $this, 'pre_get_posts_sql_browse_popular' ) );
     434                add_filter( 'posts_where', array( $this, 'pre_get_posts_sql_browse' ) );
    433435                break;
    434436        }
     
    441443
    442444    /**
    443      * Custom callback for pre_get_posts to remove the requirement for plugins to be tagged
    444      * 'popular' to show up when browsing popular plugins.
     445     * Callback to remove the requirement for plugins to be tagged with the requested
     446     * plugin_section term.
     447     *
     448     * Used for archives like `popular` or `favorites`, that all active plugins are a part of.
    445449     *
    446450     * @ignore
     
    449453     * @return string
    450454     */
    451     public function pre_get_posts_sql_browse_popular( $where ) {
     455    public function pre_get_posts_sql_browse( $where ) {
    452456        global $wpdb;
    453457
    454         remove_filter( 'posts_where', array( $this, 'pre_get_posts_sql_browse_popular' ) );
    455         $term = get_term_by( 'slug', 'popular', 'plugin_section' );
    456 
    457         return str_replace( " AND ( \n  {$wpdb->term_relationships}.term_taxonomy_id IN ({$term->term_id})\n)", '', $where );
     458        remove_filter( 'posts_where', array( $this, 'pre_get_posts_sql_browse' ) );
     459
     460        $term = get_term_by( 'slug', get_query_var( 'browse' ), 'plugin_section' );
     461
     462        if ( $term instanceof \WP_Term ) {
     463            $where = str_replace( " AND ( \n  {$wpdb->term_relationships}.term_taxonomy_id IN ({$term->term_id})\n)", '', $where );
     464        }
     465
     466        return $where;
    458467    }
    459468
Note: See TracChangeset for help on using the changeset viewer.