WordPress.org

Making WordPress.org

Changeset 4197


Ignore:
Timestamp:
10/07/2016 04:44:39 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: Switch Contributors from being stored as post meta to a taxonomy to allow for more efficient querying.

/author/$author/ / author_name queries are now based on this taxonomy rather than by the post_author.

See #1724, #1840.

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

Legend:

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

    r3888 r4197  
    6868        $result['contributors'] = array();
    6969
    70         $contributors = get_post_meta( $post_id, 'contributors', true ) ?: array( $post->user_login );
     70        if ( $contributors = get_the_terms( $post->ID, 'plugin_contributors' ) ) {
     71            $contributors = wp_list_pluck( $contributors, 'slug' );
     72        } else {
     73            $contributors = array();
     74            if ( $author = get_user_by( 'id', $post->post_author ) ) {
     75                $contributors[] = $author->user_nicename;
     76            }
     77        }
    7178        foreach ( $contributors as $contributor ) {
    7279            $user = get_user_by( 'slug', $contributor );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r4008 r4197  
    196196        ) );
    197197
    198         register_taxonomy( 'plugin_tags', 'plugin', array(
     198        register_taxonomy( 'plugin_contributors', array( 'plugin', 'force-count-to-include-all-post_status' ), array(
     199            'hierarchical'      => false,
     200            'query_var'         => 'plugin_contributor',
     201            'rewrite'           => false,
     202            'labels'            => array(
     203                'name' => __( 'Plugin Contributors', 'wporg-plugins' ),
     204                'singular_name' => __( 'Plugin Contributor', 'wporg-plugins' ),
     205            ),
     206            'public'            => true,
     207            'show_ui'           => true,
     208            'show_admin_column' => false,
     209            'capabilities'      => array(
     210                'assign_terms' => 'do_not_allow',
     211            ),
     212        ) );
     213
     214        register_taxonomy( 'plugin_tags', array( 'plugin', 'force-count-to-include-all-post_status' ), array(
    199215            'hierarchical'      => false,
    200216            'query_var'         => 'plugin_tags',
     
    453469     */
    454470    public function pre_insert_term_prevent( $term, $taxonomy ) {
    455         if ( 'plugin_tags' != $taxonomy && ! is_super_admin() ) {
     471        $allowed_taxonomies = array( 'plugin_tags', 'plugin_contributors' );
     472
     473        if ( ! in_array( $taxonomy, $allowed_taxonomies ) && ! is_super_admin() ) {
    456474            $term = new \WP_Error( 'not-allowed', __( 'You are not allowed to add terms.', 'wporg-plugins' ) );
    457475        }
     
    518536                return $posts;
    519537            }, 10, 2 );
     538        }
     539
     540        if ( isset( $wp_query->query['author_name'] ) || isset( $wp_query->query['author'] ) ) {
     541            $user = isset( $wp_query->query['author_name'] ) ? $wp_query->query['author_name'] : (get_user_by( 'id', $wp_query->query['author'])->user_nicename);
     542
     543            $wp_query->query_vars['plugin_contributor'] = $user;
     544            $wp_query->query_vars['orderby'] = 'post_title';
     545            $wp_query->query_vars['order'] = 'ASC';
     546
     547            unset( $wp_query->query_vars['author_name'], $wp_query->query_vars['author'] );
     548
    520549        }
    521550
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r3897 r4197  
    2727        'license_uri',
    2828        'upgrade_notice',
    29         'contributors',
    3029        'screenshots'
    3130    );
     
    147146        // Set tags from the readme
    148147        wp_set_post_terms( $plugin->ID, $readme->tags, 'plugin_tags' );
     148
     149        // Update the contributors list
     150        wp_set_post_terms( $plugin->ID, $readme->contributors, 'plugin_contributors' );
    149151
    150152        if ( in_array( 'adopt-me', $readme->tags ) ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/class-plugins-info-api-request.php

    r4125 r4197  
    164164            // Tags
    165165            if ( ! empty( $this->args->tag ) ) {
    166                 $query['plugin_tag'] = is_array( $this->args->tag ) ? reset( $this->args->tag ) : $this->args->tag;
     166                $query['plugin_tags'] = $this->args->tag;
    167167            }
    168168
     
    175175            if ( ! empty( $this->args->author ) ) {
    176176                $query['author_name'] = $this->args->author;
    177                 //$query['contributor_search'] = $this->args->author; // TODO
    178177            }
    179178
Note: See TracChangeset for help on using the changeset viewer.