bp_forums_get_post_extras

Get BP-specific details about a set of posts.

Description

(array) bp_forums_get_post_extras( (array) $posts ); 

Currently fetches the following: - WP userdata for each poster - BP fullname for each poster

Returns (array)

Posts with BP-data added.

Parameters (1)

0. $posts (array)
List of posts.

Usage

  1. if ( !function_exists( 'bp_forums_get_post_extras' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bp-forums-functions.php'; 
  3.  
  4. // List of posts. 
  5. $posts = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_forums_get_post_extras($posts); 
  9.  

Defined (1)

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

/bp-forums/bp-forums-functions.php  
  1. function bp_forums_get_post_extras( $posts ) { 
  2. global $wpdb; 
  3.  
  4. if ( empty( $posts ) ) 
  5. return $posts; 
  6.  
  7. $bp =buddypress); 
  8.  
  9. // Get the user ids. 
  10. foreach ( (array) $posts as $post ) $user_ids[] = $post->poster_id; 
  11. $user_ids = implode( ', ', wp_parse_id_list( $user_ids ) ); 
  12.  
  13. // Fetch the poster's user_email, user_nicename and user_login. 
  14. $poster_details = $wpdb->get_results( "SELECT u.ID as user_id, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u WHERE u.ID IN ( {$user_ids} )" ); 
  15.  
  16. for ( $i = 0, $count = count( $posts ); $i < $count; ++$i ) { 
  17. foreach ( (array) $poster_details as $poster ) { 
  18. if ( $poster->user_id == $posts[$i]->poster_id ) { 
  19. $posts[$i]->poster_email = $poster->user_email; 
  20. $posts[$i]->poster_login = $poster->user_login; 
  21. $posts[$i]->poster_nicename = $poster->user_nicename; 
  22. $posts[$i]->poster_name = $poster->display_name; 
  23.  
  24. // Fetch fullname for each poster. 
  25. if ( bp_is_active( 'xprofile' ) ) { 
  26. $poster_names = $wpdb->get_results( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ); 
  27. for ( $i = 0, $count = count( $posts ); $i < $count; ++$i ) { 
  28. foreach ( (array) $poster_names as $name ) { 
  29. if ( isset( $topics[$i] ) && $name->user_id == $topics[$i]->user_id ) 
  30. $posts[$i]->poster_name = $poster->value; 
  31.  
  32. /** 
  33. * Filters BP-specific details about a set of posts. 
  34. * @since 1.5.0 
  35. * @param array $posts Array of posts holding BP-specific details. 
  36. */