Making WordPress.org


Ignore:
Timestamp:
10/08/2016 04:23:48 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Treat /author/$author queries as taxonomy queries, and not author queries.
This is unfortunately needed as WordPress expects that the post_author of the posts is the Author for author templates, and as a result displays an incorrect archive title.

See #1840.

File:
1 edited

Legend:

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

    r4201 r4202  
    5050        add_action( 'template_redirect', array( $this, 'redirect_old_plugin_urls' ) );
    5151        add_filter( 'query_vars', array( $this, 'filter_query_vars' ) );
     52        add_filter( 'single_term_title', array( $this, 'filter_single_term_title' ) );
    5253
    5354        // oEmbed whitlisting.
     
    201202            'rewrite'           => false,
    202203            'labels'            => array(
    203                 'name' => __( 'Plugin Contributors', 'wporg-plugins' ),
    204                 'singular_name' => __( 'Plugin Contributor', 'wporg-plugins' ),
     204                'name' => __( 'Authors', 'wporg-plugins' ),
     205                'singular_name' => __( 'Author', 'wporg-plugins' ),
    205206            ),
    206207            'public'            => true,
     
    545546            $wp_query->query_vars['order'] = 'ASC';
    546547
     548            // Treat it as a taxonomy query now, not the author archive.
     549            $wp_query->is_author = false;
     550            $wp_query->is_tax = true;
     551
    547552            unset( $wp_query->query_vars['author_name'], $wp_query->query_vars['author'] );
    548 
    549553        }
    550554
     
    704708
    705709        return $vars;
     710    }
     711
     712    /**
     713     * Filters the term names for archive headers to be more useful.
     714     *
     715     * @param string $name The Term Name.
     716     * @return string The Term Name.
     717     */
     718    public function filter_single_term_title( $name ) {
     719        $term = get_queried_object();
     720        if ( ! $term || ! isset( $term->taxonomy ) ) {
     721            return $name;
     722        }
     723
     724        switch ( $term->taxonomy ) {
     725            case 'plugin_contributors':
     726                $user = get_user_by( 'slug', $term->slug );
     727                $name = $user->display_name;
     728                break;
     729        }
     730
     731        return $name;
    706732    }
    707733
Note: See TracChangeset for help on using the changeset viewer.