bp_dtheme_ajax_messages_autocomplete_results

AJAX handler for autocomplete.

Description

(string) bp_dtheme_ajax_messages_autocomplete_results(); 

Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined.

Returns (string)

HTML


Usage

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

Defined (1)

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

/bp-themes/bp-default/_inc/ajax.php  
  1. function bp_dtheme_ajax_messages_autocomplete_results() { 
  2.  
  3. // Include everyone in the autocomplete, or just friends? 
  4. $autocomplete_all =buddypress)->messages->autocomplete_all; 
  5.  
  6. $pag_page = 1; 
  7. $limit = (int) $_GET['limit'] ? $_GET['limit'] : apply_filters( 'bp_autocomplete_max_results', 10 ); 
  8.  
  9. // Get the user ids based on the search terms 
  10. if ( ! empty( $autocomplete_all ) ) { 
  11. $users = BP_Core_User::search_users( $_GET['q'], $limit, $pag_page ); 
  12.  
  13. if ( ! empty( $users['users'] ) ) { 
  14. // Build an array with the correct format 
  15. $user_ids = array(); 
  16. foreach( $users['users'] as $user ) { 
  17. if ( $user->id != bp_loggedin_user_id() ) { 
  18. $user_ids[] = $user->id; 
  19.  
  20. $user_ids = apply_filters( 'bp_core_autocomplete_ids', $user_ids, $_GET['q'], $limit ); 
  21.  
  22. } else { 
  23. if ( bp_is_active( 'friends' ) ) { 
  24. $users = friends_search_friends( $_GET['q'], bp_loggedin_user_id(), $limit, 1 ); 
  25.  
  26. // Keeping the bp_friends_autocomplete_list filter for backward compatibility 
  27. $users = apply_filters( 'bp_friends_autocomplete_list', $users, $_GET['q'], $limit ); 
  28.  
  29. if ( ! empty( $users['friends'] ) ) { 
  30. $user_ids = apply_filters( 'bp_friends_autocomplete_ids', $users['friends'], $_GET['q'], $limit ); 
  31.  
  32. if ( ! empty( $user_ids ) ) { 
  33. foreach ( $user_ids as $user_id ) { 
  34. $ud = get_userdata( $user_id ); 
  35. if ( ! $ud ) { 
  36. continue; 
  37.  
  38. // Sanitize for spaces 
  39. $username = urlencode( $ud->user_login ); 
  40. } else { 
  41. $username = $ud->user_nicename; 
  42.  
  43. // Note that the final line break acts as a delimiter for the 
  44. // autocomplete javascript and thus should not be removed 
  45. echo '<span id="link-' . esc_attr( $username ) . '" href="' . bp_core_get_user_domain( $user_id ) . '"></span>' . bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15, 'alt' => $ud->display_name ) ) . '  ' . bp_core_get_user_displayname( $user_id ) . ' (' . esc_html( $username ) . ')' . "\n"; 
  46.  
  47. exit;