bp_friends_random_members

Pull up a group of random members, and display some profile data about them.

Description

bp_friends_random_members( (int) $total_members = 5 ); 

This function is no longer used by BuddyPress core.

Parameters (1)

0. $total_members — Optional. (int) => 5
The number of members to retrieve.

Usage

  1. if ( !function_exists( 'bp_friends_random_members' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-friends/bp-friends-template.php'; 
  3.  
  4. // The number of members to retrieve. 
  5. $total_members = 5; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_friends_random_members($total_members); 
  9.  

Defined (1)

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

/bp-friends/bp-friends-template.php  
  1. function bp_friends_random_members( $total_members = 5 ) { 
  2.  
  3. if ( !$user_ids = wp_cache_get( 'friends_random_users', 'bp' ) ) { 
  4. $user_ids = BP_Core_User::get_users( 'random', $total_members ); 
  5. wp_cache_set( 'friends_random_users', $user_ids, 'bp' ); 
  6.  
  7. ?> 
  8.  
  9. <?php if ( $user_ids['users'] ) { ?> 
  10.  
  11. <ul class="item-list" id="random-members-list"> 
  12.  
  13. <?php for ( $i = 0, $count = count( $user_ids['users'] ); $i < $count; ++$i ) { ?> 
  14.  
  15. <li> 
  16. <a href="<?php echo bp_core_get_user_domain( $user_ids['users'][$i]->id ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $user_ids['users'][$i]->id, 'type' => 'thumb' ) ) ?></a> 
  17. <h5><?php echo bp_core_get_userlink( $user_ids['users'][$i]->id ) ?></h5> 
  18.  
  19. <?php if ( bp_is_active( 'xprofile' ) ) { ?> 
  20.  
  21. <?php $random_data = xprofile_get_random_profile_data( $user_ids['users'][$i]->id, true ); ?> 
  22.  
  23. <div class="profile-data"> 
  24. <p class="field-name"><?php echo $random_data[0]->name ?></p> 
  25.  
  26. <?php echo $random_data[0]->value ?> 
  27.  
  28. </div> 
  29.  
  30. <?php } ?> 
  31.  
  32. <div class="action"> 
  33.  
  34. <?php if ( bp_is_active( 'friends' ) ) { ?> 
  35.  
  36. <?php bp_add_friend_button( $user_ids['users'][$i]->id ) ?> 
  37.  
  38. <?php } ?> 
  39.  
  40. </div> 
  41. </li> 
  42.  
  43. <?php } ?> 
  44.  
  45. </ul> 
  46.  
  47. <?php } else { ?> 
  48.  
  49. <div id="message" class="info"> 
  50. <p><?php _e( "There aren't enough site members to show a random sample just yet.", buddypress ) ?></p> 
  51. </div> 
  52.  
  53. <?php } ?> 
  54. <?php