<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[5625] sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc: Support Forums: Add rewrite rules and parse query arguments for user's "Active Topics" and "Topics Replied To" views.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/5625">5625</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/5625","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-07-07 17:38:42 +0000 (Fri, 07 Jul 2017)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="http://meta.trac.wordpress.org/ticket/2470">#2470</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassdirectorycompatphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassperformanceoptimizationsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclasssupportcompatphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassusersphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassdirectorycompatphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php 2017-07-07 13:30:56 UTC (rev 5624)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php 2017-07-07 17:38:42 UTC (rev 5625)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -370,7 +370,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ||
</span><span class="cx" style="display: block; padding: 0 10px"> ( bbp_is_single_view() && ! in_array( bbp_get_view_id(), $this->compat_views() ) )
</span><span class="cx" style="display: block; padding: 0 10px"> ||
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ( bbp_is_single_user_topics() || bbp_is_single_user_replies() || get_query_var( 'wporg_single_user_reviews' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ( bbp_is_single_user_topics() || bbp_is_single_user_replies() )
+ ||
+ get_query_var( 'wporg_single_user_reviews' )
+ ||
+ get_query_var( 'wporg_single_user_active_topics' )
+ ||
+ get_query_var( 'wporg_single_user_topics_replied_to' )
</ins><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $terms = get_the_terms( $topic_id, $this->taxonomy() );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassperformanceoptimizationsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php 2017-07-07 13:30:56 UTC (rev 5624)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php 2017-07-07 17:38:42 UTC (rev 5625)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -201,6 +201,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $r;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Only look at the last year of topics for user's "Active Topics" view.
+ if ( get_query_var( 'wporg_single_user_active_topics' ) ) {
+ add_filter( 'posts_where', array( $this, 'posts_in_last_year' ) );
+ return $r;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $r['meta_key'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // has_topics() uses this by default.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '_bbp_last_active_time' == $r['meta_key'] ) {
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclasssupportcompatphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php 2017-07-07 13:30:56 UTC (rev 5624)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-support-compat.php 2017-07-07 17:38:42 UTC (rev 5625)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -29,7 +29,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Intercept feed requests prior to bbp_request_feed_trap.
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bbp_request', array( $this, 'request' ), 9 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Add views for plugin committer/contributor.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Add query vars and rewrite rules for plugin committer/contributor.
</ins><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'query_vars', array( $this, 'add_query_var' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bbp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -37,12 +37,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // on parse_query at priority 2.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'parse_query', array( $this, 'parse_query' ), 0 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Parse user's reviews query.
- add_action( 'parse_query', array( $this, 'parse_user_reviews_query' ) );
- add_filter( 'bbp_after_has_topics_parse_args', array( $this, 'parse_user_reviews_query_args' ) );
- add_filter( 'bbp_topic_pagination', array( $this, 'parse_user_reviews_pagination_args' ) );
- add_filter( 'bbp_before_title_parse_args', array( $this, 'parse_user_reviews_title_args' ) );
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Exclude compat forums from forum dropdown.
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bbp_after_get_dropdown_parse_args', array( $this, 'get_dropdown' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -214,83 +208,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Set WP_Query::bbp_is_single_user_profile to false on user's reviews page.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Add query vars for plugin committer/contributor views.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_Query $query Current query object.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $query_vars Query vars.
+ * @return array Filtered query vars.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function parse_user_reviews_query( $query ) {
- if ( get_query_var( 'wporg_single_user_reviews' ) ) {
- $query->bbp_is_single_user_profile = false;
- }
- }
-
- /**
- * Set forum ID for user's reviews query.
- *
- * @param array $args WP_Query arguments.
- * @return array Filtered query arguments.
- */
- public function parse_user_reviews_query_args( $args ) {
- if ( get_query_var( 'wporg_single_user_reviews' ) ) {
- $args['post_parent'] = Plugin::REVIEWS_FORUM_ID;
- } elseif ( bbp_is_single_user_topics() ) {
- $args['post_parent__not_in'] = array( Plugin::REVIEWS_FORUM_ID );
- }
-
- return $args;
- }
-
- /**
- * Set 'base' argument for pagination links on user's reviews page.
- *
- * @param array $args Pagination arguments.
- * @return array Filtered pagination arguments.
- */
- public function parse_user_reviews_pagination_args( $args ) {
- if ( get_query_var( 'wporg_single_user_reviews' ) ) {
- $args['base'] = bbp_get_user_profile_url( bbp_get_displayed_user_id() ) . 'reviews/';
- $args['base'] .= bbp_get_paged_slug() . '/%#%/';
- }
-
- return $args;
- }
-
- /**
- * Set title for user's reviews page.
- *
- * @param array $title Title parts.
- * @return array Filtered title parts.
- */
- public function parse_user_reviews_title_args( $title ) {
- if ( get_query_var( 'wporg_single_user_reviews' ) ) {
- if ( bbp_is_user_home() ) {
- $title['text'] = __( 'Your Reviews', 'wporg-forums' );
- } else {
- $title['text'] = get_userdata( bbp_get_user_id() )->display_name;
- /* translators: user's display name */
- $title['format'] = __( "%s's Reviews", 'wporg-forums' );
- }
- }
-
- return $title;
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> public function add_query_var( $query_vars ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $query_vars[] = 'wporg_user_login';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $query_vars[] = 'wporg_single_user_reviews';
</del><span class="cx" style="display: block; padding: 0 10px"> return $query_vars;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Add rewrite rules for plugin committer/contributor views.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> public function add_rewrite_rules() {
</span><span class="cx" style="display: block; padding: 0 10px"> $priority = 'top';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $plugin_committer_rule = bbp_get_view_slug() . '/plugin-committer/([^/]+)/';
</span><span class="cx" style="display: block; padding: 0 10px"> $plugin_contributor_rule = bbp_get_view_slug() . '/plugin-contributor/([^/]+)/';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $user_reviews_rule = bbp_get_user_slug() . '/([^/]+)/reviews/';
</del><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $feed_id = 'feed';
</span><span class="cx" style="display: block; padding: 0 10px"> $view_id = bbp_get_view_rewrite_id();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $user_id = bbp_get_user_rewrite_id();
</del><span class="cx" style="display: block; padding: 0 10px"> $paged_id = bbp_get_paged_rewrite_id();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $feed_slug = 'feed';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -309,11 +247,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_rewrite_rule( $plugin_contributor_rule . $base_rule, 'index.php?' . $view_id . '=plugin-contributor&wporg_user_login=$matches[1]', $priority );
</span><span class="cx" style="display: block; padding: 0 10px"> add_rewrite_rule( $plugin_contributor_rule . $paged_rule, 'index.php?' . $view_id . '=plugin-contributor&wporg_user_login=$matches[1]&' . $paged_id . '=$matches[2]', $priority );
</span><span class="cx" style="display: block; padding: 0 10px"> add_rewrite_rule( $plugin_contributor_rule . $feed_rule, 'index.php?' . $view_id . '=plugin-contributor&wporg_user_login=$matches[1]&' . $feed_id . '=$matches[2]', $priority );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- // Add user's reviews rewrite rules.
- add_rewrite_rule( $user_reviews_rule . $base_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1', $priority );
- add_rewrite_rule( $user_reviews_rule . $paged_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1&' . $paged_id . '=$matches[2]', $priority );
- add_rewrite_rule( $user_reviews_rule . $feed_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1&' . $feed_id . '=$matches[2]', $priority );
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassusersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php 2017-07-07 13:30:56 UTC (rev 5624)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php 2017-07-07 17:38:42 UTC (rev 5625)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -17,6 +17,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Only allow 3 published topics from a user in the first 24 hours.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'bbp_new_topic_pre_insert', array( $this, 'limit_new_user_topics' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Add query vars and rewrite rules for user's topic and review queries.
+ add_filter( 'query_vars', array( $this, 'add_query_vars' ) );
+ add_action( 'bbp_add_rewrite_rules', array( $this, 'add_rewrite_rules' ) );
+
+ // Parse user's topic and review queries.
+ add_action( 'parse_query', array( $this, 'parse_user_topics_query' ) );
+ add_filter( 'posts_groupby', array( $this, 'parse_user_topics_posts_groupby' ), 10, 2 );
+ add_filter( 'bbp_after_has_topics_parse_args', array( $this, 'parse_user_topics_query_args' ) );
+ add_filter( 'bbp_topic_pagination', array( $this, 'parse_user_topics_pagination_args' ) );
+ add_filter( 'bbp_replies_pagination', array( $this, 'parse_user_topics_pagination_args' ) );
+ add_filter( 'bbp_before_title_parse_args', array( $this, 'parse_user_topics_title_args' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -87,4 +99,175 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $topic_data;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Add query vars for user's "Reviews Written", "Active Topics",
+ * and "Topics Replied To" pages.
+ *
+ * @param array $query_vars Query vars.
+ * @return array Filtered query vars.
+ */
+ public function add_query_vars( $query_vars ) {
+ $query_vars[] = 'wporg_single_user_reviews';
+ $query_vars[] = 'wporg_single_user_active_topics';
+ $query_vars[] = 'wporg_single_user_topics_replied_to';
+ return $query_vars;
+ }
+
+ /**
+ * Add rewrite rules for user's "Reviews Written", "Active Topics",
+ * and "Topics Replied To" pages.
+ */
+ public function add_rewrite_rules() {
+ $priority = 'top';
+
+ $user_reviews_rule = bbp_get_user_slug() . '/([^/]+)/reviews/';
+ $user_active_topics_rule = bbp_get_user_slug() . '/([^/]+)/active/';
+ $user_topics_replied_to_rule = bbp_get_user_slug() . '/([^/]+)/replied-to/';
+
+ $feed_id = 'feed';
+ $user_id = bbp_get_user_rewrite_id();
+ $paged_id = bbp_get_paged_rewrite_id();
+
+ $feed_slug = 'feed';
+ $paged_slug = bbp_get_paged_slug();
+
+ $base_rule = '?$';
+ $feed_rule = $feed_slug . '/?$';
+ $paged_rule = $paged_slug . '/?([0-9]{1,})/?$';
+
+ // Add user's "Reviews Written" page rewrite rules.
+ add_rewrite_rule( $user_reviews_rule . $base_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1', $priority );
+ add_rewrite_rule( $user_reviews_rule . $paged_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1&' . $paged_id . '=$matches[2]', $priority );
+ add_rewrite_rule( $user_reviews_rule . $feed_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_reviews=1&' . $feed_id . '=$matches[2]', $priority );
+
+ // Add user's "Active Topics" page rewrite rules.
+ add_rewrite_rule( $user_active_topics_rule . $base_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_active_topics=1', $priority );
+ add_rewrite_rule( $user_active_topics_rule . $paged_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_active_topics=1&' . $paged_id . '=$matches[2]', $priority );
+ add_rewrite_rule( $user_active_topics_rule . $feed_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_active_topics=1&' . $feed_id . '=$matches[2]', $priority );
+
+ // Add user's "Topics Replied To" page rewrite rules.
+ add_rewrite_rule( $user_topics_replied_to_rule . $base_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_topics_replied_to=1', $priority );
+ add_rewrite_rule( $user_topics_replied_to_rule . $paged_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_topics_replied_to=1&' . $paged_id . '=$matches[2]', $priority );
+ add_rewrite_rule( $user_topics_replied_to_rule . $feed_rule, 'index.php?' . $user_id . '=$matches[1]&wporg_single_user_topics_replied_to=1&' . $feed_id . '=$matches[2]', $priority );
+ }
+
+ /**
+ * Set WP_Query::bbp_is_single_user_profile to false on user's "Reviews Written",
+ * "Active Topics", and "Topics Replied To" pages.
+ *
+ * @param WP_Query $query Current query object.
+ */
+ public function parse_user_topics_query( $query ) {
+ if (
+ get_query_var( 'wporg_single_user_reviews' )
+ ||
+ get_query_var( 'wporg_single_user_active_topics' )
+ ||
+ get_query_var( 'wporg_single_user_topics_replied_to' )
+ ) {
+ $query->bbp_is_single_user_profile = false;
+ }
+ }
+
+ /**
+ * Filter the GROUP BY clause on user's "Topics Replied To" page
+ * in order to group replies by topic.
+ *
+ * @param string $groupby The GROUP BY clause of the query.
+ * @param WP_Query $query The WP_Query instance.
+ * @return string Filtered GROUP BY clause.
+ */
+ public function parse_user_topics_posts_groupby( $groupby, $query ) {
+ global $wpdb;
+
+ if ( 'reply' === $query->get( 'post_type' ) && get_query_var( 'wporg_single_user_topics_replied_to' ) ) {
+ $groupby = "$wpdb->posts.post_parent";
+ }
+
+ return $groupby;
+ }
+
+ /**
+ * Set forum ID for user's Reviews query.
+ *
+ * @param array $args WP_Query arguments.
+ * @return array Filtered query arguments.
+ */
+ public function parse_user_topics_query_args( $args ) {
+ if ( get_query_var( 'wporg_single_user_reviews' ) ) {
+ $args['post_parent'] = Plugin::REVIEWS_FORUM_ID;
+ } elseif ( bbp_is_single_user_topics() || get_query_var( 'wporg_single_user_active_topics' ) ) {
+ $args['post_parent__not_in'] = array( Plugin::REVIEWS_FORUM_ID );
+ }
+
+ return $args;
+ }
+
+ /**
+ * Set 'base' argument for pagination links on user's "Reviews Written",
+ * "Active Topics", and "Topics Replied To" pages.
+ *
+ * @param array $args Pagination arguments.
+ * @return array Filtered pagination arguments.
+ */
+ public function parse_user_topics_pagination_args( $args ) {
+ if ( get_query_var( 'wporg_single_user_reviews' ) ) {
+ $args['base'] = bbp_get_user_profile_url( bbp_get_displayed_user_id() ) . 'reviews/';
+ $args['base'] .= bbp_get_paged_slug() . '/%#%/';
+ }
+
+ if ( get_query_var( 'wporg_single_user_active_topics' ) ) {
+ $args['base'] = bbp_get_user_profile_url( bbp_get_displayed_user_id() ) . 'active/';
+ $args['base'] .= bbp_get_paged_slug() . '/%#%/';
+ }
+
+ if ( get_query_var( 'wporg_single_user_topics_replied_to' ) ) {
+ $args['base'] = bbp_get_user_profile_url( bbp_get_displayed_user_id() ) . 'replied-to/';
+ $args['base'] .= bbp_get_paged_slug() . '/%#%/';
+ }
+
+ return $args;
+ }
+
+ /**
+ * Set title for user's "Reviews Written", "Active Topics",
+ * and "Topics Replied To" pages.
+ *
+ * @param array $title Title parts.
+ * @return array Filtered title parts.
+ */
+ public function parse_user_topics_title_args( $title ) {
+ if ( get_query_var( 'wporg_single_user_reviews' ) ) {
+ if ( bbp_is_user_home() ) {
+ $title['text'] = __( 'Your Reviews Written', 'wporg-forums' );
+ } else {
+ $title['text'] = get_userdata( bbp_get_user_id() )->display_name;
+ /* translators: user's display name */
+ $title['format'] = __( "%s's Reviews Written", 'wporg-forums' );
+ }
+ }
+
+ if ( get_query_var( 'wporg_single_user_active_topics' ) ) {
+ if ( bbp_is_user_home() ) {
+ $title['text'] = __( 'Your Active Topics', 'wporg-forums' );
+ } else {
+ $title['text'] = get_userdata( bbp_get_user_id() )->display_name;
+ /* translators: user's display name */
+ $title['format'] = __( "%s's Active Topics", 'wporg-forums' );
+ }
+ }
+
+ if ( get_query_var( 'wporg_single_user_topics_replied_to' ) ) {
+ if ( bbp_is_user_home() ) {
+ $title['text'] = __( "Topics You've Replied To", 'wporg-forums' );
+ } else {
+ $title['text'] = get_userdata( bbp_get_user_id() )->display_name;
+ /* translators: user's display name */
+ $title['format'] = __( 'Topics %s Has Replied To', 'wporg-forums' );
+ }
+ }
+
+ return $title;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>