bp_core_get_suggestions

BuddyPress Suggestions API for types of at-mentions.

Description

(array|WP_Error) bp_core_get_suggestions( (array) $args ); 

This is used to power BuddyPress' at-mentions suggestions, but it is flexible enough to be used for similar kinds of future requirements, or those implemented by third-party developers.

Returns (array|WP_Error)

Array of results. If there were any problems, returns a WP_Error object.

Parameters (1)

0. $args (array)
Array of args for the suggestions.

Usage

  1. if ( !function_exists( 'bp_core_get_suggestions' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // Array of args for the suggestions. 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_core_get_suggestions($args); 
  9.  

Defined (1)

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

/bp-core/bp-core-functions.php  
  1. function bp_core_get_suggestions( $args ) { 
  2. $args = bp_parse_args( $args, array(), 'get_suggestions' ); 
  3.  
  4. if ( ! $args['type'] ) { 
  5. return new WP_Error( 'missing_parameter' ); 
  6.  
  7. // Members @name suggestions. 
  8. if ( $args['type'] === 'members' ) { 
  9. $class = 'BP_Members_Suggestions'; 
  10.  
  11. // Members @name suggestions for users in a specific Group. 
  12. if ( isset( $args['group_id'] ) ) { 
  13.  
  14. } else { 
  15.  
  16. /** 
  17. * Filters the default suggestions service to use. 
  18. * Use this hook to tell BP the name of your class 
  19. * if you've built a custom suggestions service. 
  20. * @since 2.1.0 
  21. * @param string $value Custom class to use. Default: none. 
  22. * @param array $args Array of arguments for sugggestions. 
  23. */ 
  24. $class = apply_filters( 'bp_suggestions_services', '', $args ); 
  25.  
  26. if ( ! $class || ! class_exists( $class ) ) { 
  27. return new WP_Error( 'missing_parameter' ); 
  28.  
  29.  
  30. $suggestions = new $class( $args ); 
  31. $validation = $suggestions->validate(); 
  32.  
  33. if ( is_wp_error( $validation ) ) { 
  34. $retval = $validation; 
  35. } else { 
  36. $retval = $suggestions->get_suggestions(); 
  37.  
  38. /** 
  39. * Filters the available type of at-mentions. 
  40. * @since 2.1.0 
  41. * @param array|WP_Error $retval Array of results or WP_Error object. 
  42. * @param array $args Array of arguments for suggestions. 
  43. */ 
  44. return apply_filters( 'bp_core_get_suggestions', $retval, $args );