bp_friends_prime_mentions_results

Used by the Activity component's @mentions to print a JSON list of the current user's friends.

Description

bp_friends_prime_mentions_results(); 

This is intended to speed up @mentions lookups for a majority of use cases.


Usage

  1. if ( !function_exists( 'bp_friends_prime_mentions_results' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-friends/bp-friends-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_friends_prime_mentions_results(); 
  7.  

Defined (1)

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

/bp-friends/bp-friends-functions.php  
  1. function bp_friends_prime_mentions_results() { 
  2. return; 
  3.  
  4. // Bail out if the site has a ton of users. 
  5. if ( is_multisite() && wp_is_large_network( 'users' ) ) { 
  6. return; 
  7.  
  8. if ( friends_get_total_friend_count( get_current_user_id() ) > 150 ) { 
  9. return; 
  10.  
  11. $friends_query = array( 
  12. 'count_total' => '', // Prevents total count. 
  13. 'populate_extras' => false,  
  14.  
  15. 'type' => 'alphabetical',  
  16. 'user_id' => get_current_user_id(),  
  17. ); 
  18.  
  19. $friends_query = new BP_User_Query( $friends_query ); 
  20. $results = array(); 
  21.  
  22. foreach ( $friends_query->results as $user ) { 
  23. $result = new stdClass(); 
  24. $result->ID = $user->user_nicename; 
  25. $result->image = bp_core_fetch_avatar( array( 'html' => false, 'item_id' => $user->ID ) ); 
  26.  
  27. if ( ! empty( $user->display_name ) && ! bp_disable_profile_sync() ) { 
  28. $result->name = $user->display_name; 
  29. } else { 
  30. $result->name = bp_core_get_user_displayname( $user->ID ); 
  31.  
  32. $results[] = $result; 
  33.  
  34. wp_localize_script( 'bp-mentions', 'BP_Suggestions', array( 
  35. 'friends' => $results,  
  36. ) );