bp_legacy_theme_ajax_messages_autocomplete_results

AJAX handler for autocomplete.

Description

bp_legacy_theme_ajax_messages_autocomplete_results(); 

Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined.


Usage

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

Defined (1)

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

/bp-templates/bp-legacy/buddypress-functions.php  
  1. function bp_legacy_theme_ajax_messages_autocomplete_results() { 
  2.  
  3. /** 
  4. * Filters the max results default value for ajax messages autocomplete results. 
  5. * @since 1.5.0 
  6. * @param int $value Max results for autocomplete. Default 10. 
  7. */ 
  8. $limit = isset( $_GET['limit'] ) ? absint( $_GET['limit'] ) : (int) apply_filters( 'bp_autocomplete_max_results', 10 ); 
  9. $term = isset( $_GET['q'] ) ? sanitize_text_field( $_GET['q'] ) : ''; 
  10.  
  11. // Include everyone in the autocomplete, or just friends? 
  12. $only_friends = (buddypress)->messages->autocomplete_all === false ); 
  13. } else { 
  14. $only_friends = true; 
  15.  
  16. $suggestions = bp_core_get_suggestions( array( 
  17. 'limit' => $limit,  
  18. 'only_friends' => $only_friends,  
  19. 'term' => $term,  
  20. 'type' => 'members',  
  21. ) ); 
  22.  
  23. if ( $suggestions && ! is_wp_error( $suggestions ) ) { 
  24. foreach ( $suggestions as $user ) { 
  25.  
  26. // Note that the final line break acts as a delimiter for the 
  27. // autocomplete JavaScript and thus should not be removed. 
  28. printf( '<span id="%s" href="#"></span><img src="%s" style="width: 15px">   %s (%s)' . "\n",  
  29. esc_attr( 'link-' . $user->ID ),  
  30. esc_url( $user->image ),  
  31. esc_html( $user->name ),  
  32. esc_html( $user->ID ) 
  33. ); 
  34.  
  35. exit;