bp_core_get_suggestions( array $args )

BuddyPress Suggestions API for types of at-mentions.

Description

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.

Parameters

$args

(Required) Array of args for the suggestions.

Return

(array|WP_Error) Array of results. If there were any problems, returns a WP_Error object.

Source

File: bp-core/bp-core-functions.php

3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
function bp_core_get_suggestions( $args ) {
    $args = bp_parse_args( $args, array(), 'get_suggestions' );
 
    if ( ! $args['type'] ) {
        return new WP_Error( 'missing_parameter' );
    }
 
    // Members @name suggestions.
    if ( $args['type'] === 'members' ) {
        $class = 'BP_Members_Suggestions';
 
        // Members @name suggestions for users in a specific Group.
        if ( isset( $args['group_id'] ) ) {
            $class = 'BP_Groups_Member_Suggestions';
        }
 
    } else {
 
        /**
         * Filters the default suggestions service to use.
         *
         * Use this hook to tell BP the name of your class
         * if you've built a custom suggestions service.
         *
         * @since BuddyPress 2.1.0
         *
         * @param string $value Custom class to use. Default: none.
         * @param array  $args  Array of arguments for sugggestions.
         */
        $class = apply_filters( 'bp_suggestions_services', '', $args );
    }
 
    if ( ! $class || ! class_exists( $class ) ) {
        return new WP_Error( 'missing_parameter' );
    }
 
 
    $suggestions = new $class( $args );
    $validation  = $suggestions->validate();
 
    if ( is_wp_error( $validation ) ) {
        $retval = $validation;
    } else {
        $retval = $suggestions->get_suggestions();
    }
 
    /**
     * Filters the available type of at-mentions.
     *
     * @since BuddyPress 2.1.0
     *
     * @param array|WP_Error $retval Array of results or WP_Error object.
     * @param array          $args   Array of arguments for suggestions.
     */
    return apply_filters( 'bp_core_get_suggestions', $retval, $args );
}

Changelog

Changelog
Version Description
BuddyPress 2.1.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.