bp_activity_get_comment_depth

Return the current activity comment depth.

Description

(int) bp_activity_get_comment_depth( (int) $comment = 0 ); 

Returns (int)

Parameters (1)

0. $comment — Optional. (int)
Object of the activity comment or activity comment ID. Usually unnecessary when used in activity comment loop.

Usage

  1. if ( !function_exists( 'bp_activity_get_comment_depth' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-template.php'; 
  3.  
  4. // Object of the activity comment or activity comment ID. Usually unnecessary 
  5. // when used in activity comment loop. 
  6. $comment = -1; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = bp_activity_get_comment_depth($comment); 
  10.  

Defined (1)

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

/bp-activity/bp-activity-template.php  
  1. function bp_activity_get_comment_depth( $comment = 0 ) { 
  2. $depth = 0; 
  3.  
  4. // Activity comment loop takes precedence. 
  5. if ( isset( $GLOBALS['activities_template']->activity->current_comment->depth ) ) { 
  6. $depth = $GLOBALS['activities_template']->activity->current_comment->depth; 
  7.  
  8. // Get depth for activity comment manually. 
  9. } elseif ( ! empty( $comment ) ) { 
  10. // We passed an activity ID, so fetch the activity object. 
  11. if ( is_int( $comment ) ) { 
  12. $comment = new BP_Activity_Activity( $comment ); 
  13.  
  14. // Recurse through activity tree to find the depth. 
  15. if ( is_object( $comment ) && isset( $comment->type ) && 'activity_comment' === $comment->type ) { 
  16. // Fetch the entire root comment tree... ugh. 
  17. $comments = BP_Activity_Activity::get_activity_comments( $comment->item_id, 1, constant( 'PHP_INT_MAX' ) ); 
  18.  
  19. // Recursively find our comment object from the comment tree. 
  20. $iterator = new RecursiveArrayIterator( $comments ); 
  21. $recursive = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::SELF_FIRST ); 
  22. foreach ( $recursive as $cid => $cobj ) { 
  23. // Skip items that are not a comment object. 
  24. if ( ! is_numeric( $cid ) || ! is_object( $cobj ) ) { 
  25. continue; 
  26.  
  27. // We found the activity comment! Set the depth. 
  28. if ( $cid === $comment->id && isset( $cobj->depth ) ) { 
  29. $depth = $cobj->depth; 
  30. break; 
  31.  
  32. /** 
  33. * Filters the comment depth of the current activity comment. 
  34. * @since 2.0.0 
  35. * @param int $depth Depth for the current activity comment. 
  36. */