Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/29/2011 10:43:45 PM (14 years ago)
Author:
boonebgorges
Message:

Fixes total found topic count for Started Topics and Replied To tabs on user profiles. Adds template tags to check whether you're looking at Started Topics or Replied To. Fixes class name in members/single/forums.php so that AJAX pagination works correctly. Fixes #3431

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums/bp-forums-functions.php

    r4920 r5047  
    310310}
    311311
     312/**
     313 * Return the total number of topics replied to by a given user
     314 *
     315 * Uses an unfortunate technique to count unique topics, due to limitations in BB_Query.
     316 *
     317 * @package BuddyPress
     318 * @since 1.5
     319 *
     320 * @param int $user_id Defaults to displayed user, then to logged-in user
     321 * @return int $count
     322 */
     323function bp_forums_total_replied_count_for_user( $user_id = 0 ) {
     324    global $bp;
     325
     326    do_action( 'bbpress_init' );
     327
     328    if ( !$user_id )
     329        $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
     330
     331    if ( !$user_id )
     332        return 0;
     333
     334    if ( class_exists( 'BB_Query' ) ) {
     335        $query = new BB_Query( 'post', array( 'post_author_id' => $user_id, 'page' => 1, 'per_page' => -1, 'count' => true ) );
     336
     337        // Count the unique topics. No better way to do this in the bbPress query API
     338        $topics = array();
     339        foreach( $query->results as $result ) {
     340            if ( !in_array( $result->topic_id, $topics ) )
     341                $topics[] = $result->topic_id;
     342        }
     343        $count = count( $topics );
     344        $query = null;
     345    } else {
     346        $count = 0;
     347    }
     348
     349    return apply_filters( 'bp_forums_total_replied_count_for_user', $count, $user_id );
     350}
     351
    312352function bp_forums_get_topic_extras( $topics ) {
    313353    global $bp, $wpdb, $bbdb;
Note: See TracChangeset for help on using the changeset viewer.