WordPress.org

Making WordPress.org

Changeset 5083


Ignore:
Timestamp:
03/06/2017 12:26:31 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Add rewrite rules and parse query arguments for user's reviews query.

See #2007.

File:
1 edited

Legend:

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

    r5061 r5083  
    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_before_title_parse_args',     array( $this, 'parse_user_reviews_title_args' ) );
    3944
    4045            // Exclude compat forums from forum dropdown.
     
    208213    }
    209214
     215    /**
     216     * Set WP_Query::bbp_is_single_user_profile to false on user's reviews page.
     217     *
     218     * @param WP_Query $query Current query object.
     219     */
     220    public function parse_user_reviews_query( $query ) {
     221        if ( get_query_var( 'wporg_single_user_reviews' ) ) {
     222            $query->bbp_is_single_user_profile = false;
     223        }
     224    }
     225
     226    /**
     227     * Set forum ID for user's reviews query.
     228     *
     229     * @param array $args WP_Query arguments.
     230     */
     231    public function parse_user_reviews_query_args( $args ) {
     232        if ( get_query_var( 'wporg_single_user_reviews' ) ) {
     233            $args['post_parent'] = Plugin::REVIEWS_FORUM_ID;
     234        }
     235
     236        return $args;
     237    }
     238
     239    /**
     240     * Set title for user's reviews page.
     241     *
     242     * @param array $title Title parts.
     243     */
     244    public function parse_user_reviews_title_args( $title ) {
     245        if ( get_query_var( 'wporg_single_user_reviews' ) ) {
     246            if ( bbp_is_user_home() ) {
     247                $title['text'] = __( 'Your Reviews', 'wporg-forums' );
     248            } else {
     249                $title['text'] = get_userdata( bbp_get_user_id() )->display_name;
     250                /* translators: user's display name */
     251                $title['format'] = __( "%s's Reviews", 'wporg-forums' );
     252            }
     253        }
     254
     255        return $title;
     256    }
     257
    210258    public function add_query_var( $query_vars ) {
    211259        $query_vars[] = 'wporg_user_login';
     260        $query_vars[] = 'wporg_single_user_reviews';
    212261        return $query_vars;
    213262    }
     
    218267        $plugin_committer_rule   = bbp_get_view_slug() . '/plugin-committer/([^/]+)/';
    219268        $plugin_contributor_rule = bbp_get_view_slug() . '/plugin-contributor/([^/]+)/';
     269        $user_reviews_rule       = bbp_get_user_slug() . '/([^/]+)/reviews/';
    220270
    221271        $feed_id    = 'feed';
    222272        $view_id    = bbp_get_view_rewrite_id();
     273        $user_id    = bbp_get_user_rewrite_id();
    223274        $paged_id   = bbp_get_paged_rewrite_id();
    224275
     
    239290        add_rewrite_rule( $plugin_contributor_rule . $paged_rule, 'index.php?' . $view_id . '=plugin-contributor&wporg_user_login=$matches[1]&' . $paged_id . '=$matches[2]', $priority );
    240291        add_rewrite_rule( $plugin_contributor_rule . $feed_rule,  'index.php?' . $view_id . '=plugin-contributor&wporg_user_login=$matches[1]&' . $feed_id  . '=$matches[2]', $priority );
     292
     293        // Add user's reviews rewrite rules.
     294        add_rewrite_rule( $user_reviews_rule . $base_rule,  'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1',                              $priority );
     295        add_rewrite_rule( $user_reviews_rule . $paged_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1' . $paged_id . '=$matches[2]', $priority );
     296        add_rewrite_rule( $user_reviews_rule . $feed_rule,  'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1' . $feed_id  . '=$matches[2]', $priority );
    241297    }
    242298
Note: See TracChangeset for help on using the changeset viewer.