bp_activity_recurse_comment_count

Return the total number of comments to the current comment.

Description

(int) bp_activity_recurse_comment_count( (object) $comment, (int) $count = 0 ); 

This function recursively adds the total number of comments each activity child has, and returns them.

Returns (int)

$count The activity comment count.

Parameters (2)

0. $comment (object)
Activity comment object.
1. $count — Optional. (int)
The current iteration count.

Usage

  1. if ( !function_exists( 'bp_activity_recurse_comment_count' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-template.php'; 
  3.  
  4. // Activity comment object. 
  5. $comment = null; 
  6.  
  7. // The current iteration count. 
  8. $count = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_activity_recurse_comment_count($comment, $count); 
  12.  

Defined (1)

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

/bp-activity/bp-activity-template.php  
  1. function bp_activity_recurse_comment_count( $comment, $count = 0 ) { 
  2.  
  3. // Copy the count. 
  4. $new_count = $count; 
  5.  
  6. // Loop through children and recursively count comments. 
  7. if ( ! empty( $comment->children ) ) { 
  8. foreach ( (array) $comment->children as $comment ) { 
  9. $new_count++; 
  10. $new_count = bp_activity_recurse_comment_count( $comment, $new_count ); 
  11.  
  12. /** 
  13. * Filters the total number of comments for the current comment. 
  14. * @since 2.1.0 
  15. * @param int $new_count New total count for the current comment. 
  16. * @param object $comment Activity comment object. 
  17. * @param int $count Current iteration count for the current comment. 
  18. */ 
  19. return apply_filters( 'bp_activity_recurse_comment_count', $new_count, $comment, $count );