bp_forums_total_replied_count_for_user

Return the total number of topics replied to by a given user.

Description

(int) bp_forums_total_replied_count_for_user( (int) $user_id = 0, (string) $type = 'active' ); 

Uses an unfortunate technique to count unique topics, due to limitations in BB_Query.

Returns (int)

$count Topic count.

Parameters (2)

0. $user_id — Optional. (int)
ID of the user whose replied topics are being counted. Defaults to displayed user, then to logged-in user.
1. $type — Optional. (string) => 'active'
Forum thread type.

Usage

  1. if ( !function_exists( 'bp_forums_total_replied_count_for_user' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bp-forums-functions.php'; 
  3.  
  4. // ID of the user whose replied topics are being counted. 
  5. // Defaults to displayed user, then to logged-in user. 
  6. $user_id = -1; 
  7.  
  8. // Forum thread type. 
  9. $type = 'active'; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = bp_forums_total_replied_count_for_user($user_id, $type); 
  13.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bp-forums-functions.php  
  1. function bp_forums_total_replied_count_for_user( $user_id = 0, $type = 'active' ) { 
  2.  
  3. /** This action is documented in bp-forums/bp-forums-screens.php */ 
  4.  
  5. if ( !$user_id ) 
  6.  
  7. if ( !$user_id ) 
  8. return 0; 
  9.  
  10. if ( class_exists( 'BB_Query' ) ) { 
  11. $query = new BB_Query( 'post', array( 'post_author_id' => $user_id, 'page' => 1, 'per_page' => -1, 'count' => true ) ); 
  12.  
  13. // Count the unique topics. No better way to do this in the bbPress query API. 
  14. $topics = array(); 
  15. foreach( $query->results as $result ) { 
  16. if ( !in_array( $result->topic_id, $topics ) ) 
  17. $topics[] = $result->topic_id; 
  18.  
  19. // Even more unfortunate. If this is filtered by 'unreplied', we have to requery. 
  20. if ( 'unreplied' == $type ) { 
  21. $topic_ids = implode( ', ', $topics ); 
  22. $topics_query = new BB_Query( 'topic', array( 'topic_id' => $topic_ids, 'page' => 1, 'per_page' => -1, 'post_count' => 1 ) ); 
  23. $count = count( $topics_query->results ); 
  24. } else { 
  25. $count = count( $topics ); 
  26. $query = null; 
  27. } else { 
  28. $count = 0; 
  29.  
  30. /** 
  31. * Filters the total number of topics replied to by a given user. 
  32. * @since 1.5.0 
  33. * @param int $count Total number of topics replied to by a given user. 
  34. * @param int $user_id The user ID. 
  35. */