Index: /trunk/src/includes/extend/buddypress/groups.php
===================================================================
--- /trunk/src/includes/extend/buddypress/groups.php	(revision 7315)
+++ /trunk/src/includes/extend/buddypress/groups.php	(revision 7316)
@@ -117,4 +117,5 @@
 		add_filter( 'bbp_topic_pagination',      array( $this, 'topic_pagination'   ) );
 		add_filter( 'bbp_replies_pagination',    array( $this, 'replies_pagination' ) );
+		add_filter( 'bbp_get_global_object',     array( $this, 'rewrite_pagination' ), 10, 2 );
 
 		// Tweak the redirect field
@@ -614,5 +615,5 @@
 		// Redirect after save when not in admin
 		if ( ! is_admin() ) {
-			bp_core_redirect( trailingslashit( bp_get_group_permalink( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) );
+			bp_core_redirect( trailingslashit( $this->group_url( buddypress()->groups->current_group ) . '/admin/' . $this->slug ) );
 		}
 	}
@@ -1270,5 +1271,5 @@
 			$topic        = bbp_get_topic( $topic_id );
 			$topic_hash   = '#post-' . $topic_id;
-			$redirect_url = trailingslashit( bp_get_group_permalink( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name ) . $topic_hash;
+			$redirect_url = trailingslashit( $this->group_url( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name ) . $topic_hash;
 		}
 
@@ -1289,5 +1290,5 @@
 			$reply_page     = ceil( (int) $reply_position / (int) bbp_get_replies_per_page() );
 			$reply_hash     = '#post-' . $reply_id;
-			$topic_url      = trailingslashit( bp_get_group_permalink( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name );
+			$topic_url      = trailingslashit( $this->group_url( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name );
 
 			// Don't include pagination if on first page
@@ -1445,4 +1446,56 @@
 
 	/**
+	 * Get the URL for a group.
+	 *
+	 * @since 2.6.14
+	 *
+	 * @param int $group_id
+	 * @return string
+	 */
+	private function group_url( $group_id = 0 ) {
+
+		// Default return value
+		$retval = '';
+
+		// BuddyPress < 12.0 (deprecated code is intentionally included)
+		if ( function_exists( 'bp_get_group_permalink' ) ) {
+			$retval = bp_get_group_permalink( $group_id );
+
+		// BuddyPress > 12.0 (rewrite rules)
+		} elseif ( function_exists( 'bp_get_group_url' ) ) {
+			$retval = bp_get_group_url( $group_id );
+		}
+
+		// Return
+		return $retval;
+	}
+
+	/**
+	 * Get the management URL for a group.
+	 *
+	 * @since 2.6.14
+	 *
+	 * @param int $group_id
+	 * @return string
+	 */
+	private function group_manage_url( $group_id = 0 ) {
+
+		// Default return value
+		$retval = '';
+
+		// BuddyPress < 12.0 (deprecated code is intentionally included)
+		if ( function_exists( 'bp_get_group_admin_permalink' ) ) {
+			$retval = bp_get_group_admin_permalink( $group_id );
+
+		// BuddyPress > 12.0 (rewrite rules)
+		} elseif ( function_exists( 'bp_get_group_manage_url' ) ) {
+			$retval = bp_get_group_manage_url( $group_id );
+		}
+
+		// Return
+		return $retval;
+	}
+
+	/**
 	 * Maybe map a bbPress forum/topic/reply permalink to the corresponding group
 	 *
@@ -1494,11 +1547,10 @@
 		$group    = groups_get_group( array( 'group_id' => $group_id ) );
 
-		if ( bp_is_group_admin_screen( $this->slug ) ) {
-			$group_permalink = trailingslashit( bp_get_group_admin_permalink( $group ) );
-		} else {
-			$group_permalink = trailingslashit( bp_get_group_permalink( $group ) );
-		}
-
-		return trailingslashit( trailingslashit( $group_permalink . $this->slug ) . $url_end );
+		// Admin
+		$group_permalink = bp_is_group_admin_screen( $this->slug )
+			? $this->group_manage_url( $group )
+			: $this->group_url( $group );
+
+		return trailingslashit( trailingslashit( trailingslashit( $group_permalink ) . $this->slug ) . $url_end );
 	}
 
@@ -1642,4 +1694,68 @@
 		return $args;
 	}
+
+    /**
+     * Fixes rewrite pagination in BuddyPress Group Forums & Topics.
+	 *
+     * Required for compatibility with BuddyPress > 12.0, where the /groups/
+	 * rewrite rule will be caught before bbPress's /page/ rule.
+	 *
+	 * @since 2.6.14
+	 *
+	 * @param  object object  Verified object
+	 * @param  string $type   Type of variable to check with `is_a()`
+	 * @return mixed  $object Verified object if valid, Default or null if invalid
+     */
+    public function rewrite_pagination( $object, $type = '' ) {
+
+		// Bail if wrong global
+        if ( 'wp_query' !== $type ) {
+            return $object;
+        }
+
+		// Bail if not inside a BuddyPress Group
+        if ( ! bp_is_group() ) {
+            return $object;
+        }
+
+		// Bail if not inside a BuddyPress Group Forum
+        if ( ! bp_is_current_action( 'forum' ) ) {
+            return $object;
+        }
+
+		// Default "paged" value
+        $page_number = null;
+
+        // Can't use bbp_is_single_topic() because it triggers a loop.
+        $is_single_topic = bp_is_action_variable( 'topic', 0 );
+
+		// Single Topic
+        if ( true === $is_single_topic ) {
+
+			// Get the page number from 3rd position
+            if ( bp_is_action_variable( 'page', 2 ) ) {
+                $page_number = bp_action_variable( 3 );
+            }
+
+		// Single Forum
+        } else {
+
+			// Get the page number from 1st position
+            if ( bp_is_action_variable( 'page', 0 ) ) {
+                $page_number = bp_action_variable( 1 );
+            }
+        }
+
+		// Bail if no page number
+        if ( empty( $page_number ) ) {
+            return $object;
+        }
+
+		// Set the 'paged' WP_Query var to the new action-based value
+        $object->set( 'paged', $page_number );
+
+		// Return the filtered/modified object
+        return $object;
+    }
 
 	/**
@@ -1681,5 +1797,5 @@
 		$group_id 	 = $group_ids[0];
 		$group    	 = groups_get_group( array( 'group_id' => $group_id ) );
-		$group_link  = trailingslashit( bp_get_group_permalink( $group ) );
+		$group_link  = trailingslashit( $this->group_url( $group ) );
 		$redirect_to = trailingslashit( $group_link . $this->slug );
 
