WordPress.org

Making WordPress.org

Changeset 4214


Ignore:
Timestamp:
10/11/2016 08:27:15 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: Add a plugin_committer taxonomy and sync it with the svn_access table.
The taxonomy is only used to ease querying, and allows for /author/$self to display both plugins you're listed as a contributor for and those you have commit access for.

See #2111

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
3 edited

Legend:

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

    r4213 r4214  
    4040        add_action( 'init', array( $this, 'register_shortcodes' ) );
    4141        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
    42         add_filter( 'post_type_link', array( $this, 'package_link' ), 10, 2 );
    43         add_filter( 'term_link', array( $this, 'term_link' ), 10, 2 );
    44         add_action( 'pre_get_posts', array( $this, 'use_plugins_in_query' ) );
     42        add_filter( 'post_type_link', array( $this, 'filter_post_type_link' ), 10, 2 );
     43        add_filter( 'term_link', array( $this, 'filter_term_link' ), 10, 2 );
     44        add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
    4545        add_filter( 'rest_api_allowed_post_types', array( $this, 'filter_allowed_post_types' ) );
    4646        add_filter( 'pre_update_option_jetpack_options', array( $this, 'filter_jetpack_options' ) );
     
    209209        ) );
    210210
     211        register_taxonomy( 'plugin_committers', array( 'plugin', 'force-count-to-include-all-post_status' ), array(
     212            'hierarchical'      => false,
     213            'query_var'         => 'plugin_committer',
     214            'rewrite'           => false,
     215            'labels'            => array(
     216                'name' => __( 'Committers', 'wporg-plugins' ),
     217                'singular_name' => __( 'Committer', 'wporg-plugins' ),
     218            ),
     219            'public'            => true,
     220            'show_ui'           => true,
     221            'show_admin_column' => false,
     222            'capabilities'      => array(
     223                'assign_terms' => 'do_not_allow',
     224            ),
     225        ) );
     226
    211227        register_taxonomy( 'plugin_tags', array( 'plugin', 'force-count-to-include-all-post_status' ), array(
    212228            'hierarchical'      => false,
     
    430446     * @return string
    431447     */
    432     public function package_link( $link, $post ) {
     448    public function filter_post_type_link( $link, $post ) {
    433449        if ( 'plugin' !== $post->post_type ) {
    434450            return $link;
     
    445461     * @return string|false
    446462     */
    447     public function term_link( $term_link, $term ) {
     463    public function filter_term_link( $term_link, $term ) {
    448464        if ( 'plugin_business_model' == $term->taxonomy ) {
    449465            return false;
     
    460476     * @param \WP_Query $wp_query The WordPress Query object.
    461477     */
    462     public function use_plugins_in_query( $wp_query ) {
     478    public function pre_get_posts( $wp_query ) {
    463479        if ( is_admin() ) {
    464480            return;
    465481        }
    466482
     483        // Unless otherwise specified, we start off by querying for publish'd plugins.
    467484        if ( empty( $wp_query->query_vars['pagename'] ) && ( empty( $wp_query->query_vars['post_type'] ) || 'post' == $wp_query->query_vars['post_type'] ) ) {
    468485            $wp_query->query_vars['post_type']   = array( 'plugin' );
     
    470487        }
    471488
     489        // By default, if no query is made, we're querying /browse/featured/
    472490        if ( empty( $wp_query->query ) ) {
    473491            $wp_query->query_vars['browse'] = 'featured';
    474492        }
    475493
     494        // Set up custom queries for the /browse/ URLs
    476495        switch ( $wp_query->get( 'browse' ) ) {
    477496            case 'favorites':
     
    502521        }
    503522
     523        // For /browse/ requests, we conditionally need to avoid querying the taxonomy for most views (as it's handled in code above)
    504524        if ( isset( $wp_query->query['browse'] ) && 'beta' != $wp_query->query['browse'] && 'featured' != $wp_query->query['browse'] ) {
    505525            unset( $wp_query->query_vars['browse'] );
     
    517537        }
    518538
     539        // Holds a truthful value when viewing an author archive for the current user, or a plugin reviewer viewing an author archive
     540        $viewing_own_author_archive = false;
     541
     542        // Author Archives need to be created
    519543        if ( isset( $wp_query->query['author_name'] ) || isset( $wp_query->query['author'] ) ) {
    520544            $user = isset( $wp_query->query['author_name'] ) ? $wp_query->query['author_name'] : (get_user_by( 'id', $wp_query->query['author'])->user_nicename);
    521545
    522             $wp_query->query_vars['plugin_contributor'] = $user;
     546            $viewing_own_author_archive = is_user_logged_in() && ( current_user_can( 'plugin_review' ) || 0 === strcasecmp( $user, wp_get_current_user()->user_nicename ) );
     547
     548            // Author archives by default list plugins you're a contributor on.
     549            $wp_query->query_vars['tax_query'] = array(
     550                'relation' => 'OR',
     551                array(
     552                    'taxonomy' => 'plugin_contributors',
     553                    'field' => 'slug',
     554                    'terms' => $user
     555                )
     556            );
     557
     558            // Author archives for self include plugins you're a committer on, not just publically a contributor
     559            // Plugin Reviewers also see plugins you're a committer on here.
     560            if ( $viewing_own_author_archive ) {
     561                $wp_query->query_vars['tax_query'][] = array(
     562                    'taxonomy' => 'plugin_committers',
     563                    'field' => 'slug',
     564                    'terms' => $user
     565                );
     566            }
     567
     568            // TODO: Make plugins owned by `post_author = $current_user_id` show up here when they're not-publish?
     569
    523570            $wp_query->query_vars['orderby'] = 'post_title';
    524571            $wp_query->query_vars['order'] = 'ASC';
     
    532579
    533580        // For singular requests, or self-author profile requests allow restricted post_status items to show on the front-end.
    534         if ( is_user_logged_in() && (
    535             !empty( $wp_query->query_vars['name'] ) ||
    536             (
    537                 !empty( $wp_query->query_vars['plugin_contributor'] ) &&
    538                 (
    539                     current_user_can( 'plugin_review' ) ||
    540                     0 === strcasecmp( $wp_query->query_vars['plugin_contributor'], wp_get_current_user()->user_nicename )
    541                 )
    542             ) )
    543         ) {
     581        if ( $viewing_own_author_archive || ( is_user_logged_in() && !empty( $wp_query->query_vars['name'] ) ) ) {
     582
    544583            $wp_query->query_vars['post_status'] = array( 'pending', 'approved', 'publish', 'closed', 'disabled' );
    545584
     
    756795        switch ( $term->taxonomy ) {
    757796            case 'plugin_contributors':
     797            case 'plugin_committers':
    758798                $user = get_user_by( 'slug', $term->slug );
    759799                $name = $user->display_name;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php

    r3830 r4214  
    122122
    123123    /**
     124     * Syncs the list of committers from the svn_access table to a taxonomy.
     125     *
     126     * @static
     127     * @param string $plugin_slug The Plugin Slug to sync.
     128     */
     129    public static function sync_plugin_committers_with_taxonomy( $plugin_slug ) {
     130        $post = Plugin_Directory::get_plugin_post( $plugin_slug );
     131        if ( ! $post ) {
     132            return false;
     133        }
     134
     135        $committer_slugs = array();
     136        foreach ( Tools::get_plugin_committers( $plugin_slug ) as $committer ) {
     137            $user = get_user_by( 'login', $committer );
     138            if ( $user ) {
     139                $committer_slugs[] = $user->user_nicename;
     140            }
     141        }
     142
     143        wp_set_post_terms( $post->ID, $committer_slugs, 'plugin_committers' );
     144    }
     145
     146    /**
    124147     * Grant a user RW access to a plugin.
    125148     *
     
    149172        }
    150173
    151         wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
    152         wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
    153 
    154         return (bool) $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array(
     174        $result = (bool) $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array(
    155175            'path'   => "/{$plugin_slug}",
    156176            'user'   => $user->user_login,
    157177            'access' => 'rw',
    158178        ) );
     179
     180        wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
     181        wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
     182        Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
     183
     184        return $result;
    159185    }
    160186
     
    180206        }
    181207
    182         wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
    183         wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
    184 
    185         return $wpdb->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array(
     208        $result = (bool) $wpdb->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array(
    186209            'path' => "/{$plugin_slug}",
    187210            'user' => $user->user_login,
    188211        ) );
     212
     213        wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' );
     214        wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' );
     215        Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
     216
     217        return $result;
    189218    }
    190219
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r4212 r4214  
    149149        // Update the contributors list
    150150        wp_set_post_terms( $plugin->ID, $readme->contributors, 'plugin_contributors' );
     151
     152        // Update the committers list
     153        Tools::sync_plugin_committers_with_taxonomy( $plugin->post_name );
    151154
    152155        if ( in_array( 'adopt-me', $readme->tags ) ) {
Note: See TracChangeset for help on using the changeset viewer.