WordPress.org

Making WordPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.