Making WordPress.org


Ignore:
Timestamp:
07/07/2017 05:38:42 PM (9 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Add rewrite rules and parse query arguments for user's "Active Topics" and "Topics Replied To" views.

Move user's "Reviews Written" view handling to Users class.

See #2470.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php

    r5286 r5625  
    3030                        add_filter( 'bbp_request', array( $this, 'request' ), 9 );
    3131
    32                         // Add views for plugin committer/contributor.
     32                        // Add query vars and rewrite rules for plugin committer/contributor.
    3333                        add_filter( 'query_vars',            array( $this, 'add_query_var' ) );
    3434                        add_action( 'bbp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ) );
     
    3737                        // on parse_query at priority 2.
    3838                        add_action( 'parse_query',           array( $this, 'parse_query' ), 0 );
    39 
    40                         // Parse user's reviews query.
    41                         add_action( 'parse_query',                     array( $this, 'parse_user_reviews_query' ) );
    42                         add_filter( 'bbp_after_has_topics_parse_args', array( $this, 'parse_user_reviews_query_args' ) );
    43                         add_filter( 'bbp_topic_pagination',            array( $this, 'parse_user_reviews_pagination_args' ) );
    44                         add_filter( 'bbp_before_title_parse_args',     array( $this, 'parse_user_reviews_title_args' ) );
    4539
    4640                        // Exclude compat forums from forum dropdown.
     
    215209
    216210        /**
    217          * Set WP_Query::bbp_is_single_user_profile to false on user's reviews page.
    218          *
    219          * @param WP_Query $query Current query object.
    220          */
    221         public function parse_user_reviews_query( $query ) {
    222                 if ( get_query_var( 'wporg_single_user_reviews' ) ) {
    223                         $query->bbp_is_single_user_profile = false;
    224                 }
    225         }
    226 
    227         /**
    228          * Set forum ID for user's reviews query.
    229          *
    230          * @param array $args WP_Query arguments.
    231          * @return array Filtered query arguments.
    232          */
    233         public function parse_user_reviews_query_args( $args ) {
    234                 if ( get_query_var( 'wporg_single_user_reviews' ) ) {
    235                         $args['post_parent'] = Plugin::REVIEWS_FORUM_ID;
    236                 } elseif ( bbp_is_single_user_topics() ) {
    237                         $args['post_parent__not_in'] = array( Plugin::REVIEWS_FORUM_ID );
    238                 }
    239 
    240                 return $args;
    241         }
    242 
    243         /**
    244          * Set 'base' argument for pagination links on user's reviews page.
    245          *
    246          * @param array $args Pagination arguments.
    247          * @return array Filtered pagination arguments.
    248          */
    249         public function parse_user_reviews_pagination_args( $args ) {
    250                 if ( get_query_var( 'wporg_single_user_reviews' ) ) {
    251                         $args['base']  = bbp_get_user_profile_url( bbp_get_displayed_user_id() ) . 'reviews/';
    252                         $args['base'] .= bbp_get_paged_slug() . '/%#%/';
    253                 }
    254 
    255                 return $args;
    256         }
    257 
    258         /**
    259          * Set title for user's reviews page.
    260          *
    261          * @param array $title Title parts.
    262          * @return array Filtered title parts.
    263          */
    264         public function parse_user_reviews_title_args( $title ) {
    265                 if ( get_query_var( 'wporg_single_user_reviews' ) ) {
    266                         if ( bbp_is_user_home() ) {
    267                                 $title['text'] = __( 'Your Reviews', 'wporg-forums' );
    268                         } else {
    269                                 $title['text'] = get_userdata( bbp_get_user_id() )->display_name;
    270                                 /* translators: user's display name */
    271                                 $title['format'] = __( "%s's Reviews", 'wporg-forums' );
    272                         }
    273                 }
    274 
    275                 return $title;
    276         }
    277 
     211         * Add query vars for plugin committer/contributor views.
     212         *
     213         * @param array $query_vars Query vars.
     214         * @return array Filtered query vars.
     215         */
    278216        public function add_query_var( $query_vars ) {
    279217                $query_vars[] = 'wporg_user_login';
    280                 $query_vars[] = 'wporg_single_user_reviews';
    281218                return $query_vars;
    282219        }
    283220
     221        /**
     222         * Add rewrite rules for plugin committer/contributor views.
     223         */
    284224        public function add_rewrite_rules() {
    285225                $priority   = 'top';
     
    287227                $plugin_committer_rule   = bbp_get_view_slug() . '/plugin-committer/([^/]+)/';
    288228                $plugin_contributor_rule = bbp_get_view_slug() . '/plugin-contributor/([^/]+)/';
    289                 $user_reviews_rule       = bbp_get_user_slug() . '/([^/]+)/reviews/';
    290229
    291230                $feed_id    = 'feed';
    292231                $view_id    = bbp_get_view_rewrite_id();
    293                 $user_id    = bbp_get_user_rewrite_id();
    294232                $paged_id   = bbp_get_paged_rewrite_id();
    295233
     
    310248                add_rewrite_rule( $plugin_contributor_rule . $paged_rule, 'index.php?' . $view_id . '=plugin-contributor&wporg_user_login=$matches[1]&' . $paged_id . '=$matches[2]', $priority );
    311249                add_rewrite_rule( $plugin_contributor_rule . $feed_rule,  'index.php?' . $view_id . '=plugin-contributor&wporg_user_login=$matches[1]&' . $feed_id  . '=$matches[2]', $priority );
    312 
    313                 // Add user's reviews rewrite rules.
    314                 add_rewrite_rule( $user_reviews_rule . $base_rule,  'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1',                               $priority );
    315                 add_rewrite_rule( $user_reviews_rule . $paged_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1&' . $paged_id . '=$matches[2]', $priority );
    316                 add_rewrite_rule( $user_reviews_rule . $feed_rule,  'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1&' . $feed_id  . '=$matches[2]', $priority );
    317250        }
    318251
Note: See TracChangeset for help on using the changeset viewer.