Making WordPress.org

Changeset 3338


Ignore:
Timestamp:
06/12/2016 10:15:16 AM (8 years ago)
Author:
obenland
Message:

Plugin Directory: Treat plugin sections like the archive they are.

Adds a special case for the term 'popular' to not require the term to be
assigned to a plugin for the plugin to show up in the term archive.

Fixes #1757.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
2 edited

Legend:

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

    r3335 r3338  
    9999        register_taxonomy( 'plugin_section', 'plugin', array(
    100100            'hierarchical'      => true,
    101             'query_var'         => 'plugin_section',
     101            'query_var'         => 'browse',
    102102            'rewrite'           => false,
    103103            'public'            => true,
     
    109109            ),
    110110            'labels'            => array(
    111                 'name' => __( 'Plugin Sections', 'wporg-plugins' ),
     111                'name' => __( 'Browse', 'wporg-plugins' ),
    112112            ),
    113113        ) );
     
    409409
    410410        switch ( get_query_var( 'browse' ) ) {
    411             case 'beta':
    412                 $wp_query->query_vars['plugin_section'] = 'beta';
    413                 break;
    414 
    415             case 'featured':
    416                 $wp_query->query_vars['plugin_section'] = 'featured';
    417                 break;
    418 
    419411            case 'favorites':
    420412                $favorites_user = get_current_user_id();
     
    442434                $wp_query->query_vars['orderby'] = 'meta_value_num';
    443435                $wp_query->query_vars['meta_key'] = 'active_installs';
     436
     437                add_filter( 'posts_where', array( $this, 'pre_get_posts_sql_browse_popular' ) );
    444438                break;
    445439        }
    446 
     440    }
     441
     442    /**
     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     *
     446     * @ignore
     447     *
     448     * @param string $where WHERE clause.
     449     * @return string
     450     */
     451    public function pre_get_posts_sql_browse_popular( $where ) {
     452        global $wpdb;
     453
     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 );
    447458    }
    448459
     
    613624    /**
    614625     * Filters the value of tax_inputs before saving.
    615      * 
     626     *
    616627     * Used both in the admin and the uploader.
    617628     *
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/front-page.php

    r3300 r3338  
    2626    <main id="main" class="site-main" role="main">
    2727
    28         <?php foreach ( $sections as $section_slug => $section_title ) :
     28        <?php foreach ( $sections as $browse => $section_title ) :
    2929            $section_args = array(
    30                 'post_type'       => 'plugin',
    31                 'posts_per_page'  => 4,
    32                 'plugin_section' => $section_slug,
     30                'post_type'      => 'plugin',
     31                'posts_per_page' => 4,
     32                'browse'         => $browse,
    3333            );
    3434
    35             if ( 'popular' === $section_slug ) :
     35            if ( 'popular' === $browse ) :
    3636                $section_args['meta_key'] = 'active_installs';
    3737                $section_args['orderby']  = 'meta_value_num';
    38                 unset( $section_args['plugin_section'] );
     38                unset( $section_args['browse'] );
    3939            endif;
    4040
    4141            $section_query = new \WP_Query( $section_args );
    42         ?>
     42            ?>
    4343
    4444            <section class="plugin-section">
    4545                <header class="section-header">
    4646                    <h1 class="section-title"><?php echo esc_html( $section_title ); ?></h1>
    47                     <a class="section-link" href="<?php echo esc_url( home_url( "browse/$section_slug/" ) ); ?>"><?php _ex( 'See all', 'plugins', 'wporg-plugins' ); ?></a>
     47                    <a class="section-link" href="<?php echo esc_url( home_url( "browse/$browse/" ) ); ?>"><?php _ex( 'See all', 'plugins', 'wporg-plugins' ); ?></a>
    4848                </header>
    4949
    5050                <?php
    51                     while ( $section_query->have_posts() ) :
    52                         $section_query->the_post();
     51                while ( $section_query->have_posts() ) :
     52                    $section_query->the_post();
    5353
    54                         get_template_part( 'template-parts/plugin', 'index' );
    55                     endwhile;
     54                    get_template_part( 'template-parts/plugin', 'index' );
     55                endwhile;
    5656                ?>
    5757            </section>
     
    6363    <aside id="secondary" class="widget-area" role="complementary">
    6464        <?php
    65             the_widget( 'WP_Widget_Text', array(
    66                 'title' => 'Plugin Authors',
    67                 'text'  => 'Now what are the possibilities of warp drive? Cmdr Riker\'s nervous system has been invaded by an unknown microorganism. The organisms fuse to the nerve, intertwining at the molecular level. That\'s why the transporter\'s biofilters couldn\'t extract it.',
    68             ), $widget_args );
     65        the_widget( 'WP_Widget_Text', array(
     66            'title' => 'Plugin Authors',
     67            'text'  => 'Now what are the possibilities of warp drive? Cmdr Riker\'s nervous system has been invaded by an unknown microorganism. The organisms fuse to the nerve, intertwining at the molecular level. That\'s why the transporter\'s biofilters couldn\'t extract it.',
     68        ), $widget_args );
    6969
    70             the_widget( 'WP_Widget_Text', array(
    71                 'title' => 'Plugin Reviewers',
    72                 'text'  => 'Shields up. I recommend we transfer power to phasers and arm the photon torpedoes. Something strange on the detector circuit. The weapons must have disrupted our communicators.',
    73             ), $widget_args );
     70        the_widget( 'WP_Widget_Text', array(
     71            'title' => 'Plugin Reviewers',
     72            'text'  => 'Shields up. I recommend we transfer power to phasers and arm the photon torpedoes. Something strange on the detector circuit. The weapons must have disrupted our communicators.',
     73        ), $widget_args );
    7474
    75             the_widget( 'WP_Widget_Text', array(
    76                 'title' => 'Plugin Handbook',
    77                 'text'  => 'Communication is not possible. The shuttle has no power. Using the gravitational pull of a star to slingshot back in time? We are going to Starbase Montgomery for Engineering consultations prompted by minor read-out anomalies.',
    78             ), $widget_args );
     75        the_widget( 'WP_Widget_Text', array(
     76            'title' => 'Plugin Handbook',
     77            'text'  => 'Communication is not possible. The shuttle has no power. Using the gravitational pull of a star to slingshot back in time? We are going to Starbase Montgomery for Engineering consultations prompted by minor read-out anomalies.',
     78        ), $widget_args );
    7979        ?>
    8080    </aside><!-- #secondary -->
    81 <?php
     81    <?php
    8282get_footer();
Note: See TracChangeset for help on using the changeset viewer.