bp_core_filter_comments

Filter the blog post comments array and insert BuddyPress URLs for users.

Description

(array) bp_core_filter_comments( (array) $comments, (int) $post_id ); 

Returns (array)

$comments The modified comment array.

Parameters (2)

0. $comments (array)
The array of comments supplied to the comments template.
1. $post_id (int)
The post id.

Usage

  1. if ( !function_exists( 'bp_core_filter_comments' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-filters.php'; 
  3.  
  4. // The array of comments supplied to the comments template. 
  5. $comments = array(); 
  6.  
  7. // The post id. 
  8. $post_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_core_filter_comments($comments, $post_id); 
  12.  

Defined (1)

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

/bp-core/bp-core-filters.php  
  1. function bp_core_filter_comments( $comments, $post_id ) { 
  2. global $wpdb; 
  3.  
  4. foreach( (array) $comments as $comment ) { 
  5. if ( $comment->user_id ) 
  6. $user_ids[] = $comment->user_id; 
  7.  
  8. if ( empty( $user_ids ) ) 
  9. return $comments; 
  10.  
  11. $user_ids = implode( ', ', wp_parse_id_list( $user_ids ) ); 
  12.  
  13. if ( !$userdata = $wpdb->get_results( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) 
  14. return $comments; 
  15.  
  16. foreach( (array) $userdata as $user ) 
  17. $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login ); 
  18.  
  19. foreach( (array) $comments as $i => $comment ) { 
  20. if ( !empty( $comment->user_id ) ) { 
  21. if ( !empty( $users[$comment->user_id] ) ) 
  22. $comments[$i]->comment_author_url = $users[$comment->user_id]; 
  23.  
  24. return $comments;