BP_Members_Suggestions::get_suggestions()

Find and return a list of username suggestions that match the query.


Description Description


Return Return

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


Top ↑

Source Source

File: bp-core/classes/class-bp-members-suggestions.php

	public function get_suggestions() {
		$user_query = array(
			'count_total'     => '',  // Prevents total count.
			'populate_extras' => false,
			'type'            => 'alphabetical',

			'page'            => 1,
			'per_page'        => $this->args['limit'],
			'search_terms'    => $this->args['term'],
			'search_wildcard' => 'right',
		);

		// Only return matches of friends of this user.
		if ( $this->args['only_friends'] && is_user_logged_in() ) {
			$user_query['user_id'] = get_current_user_id();
		}

		/**
		 * Filters the members suggestions query args.
		 *
		 * @since 2.1.0
		 *
		 * @param array                  $user_query Array of query arguments.
		 * @param BP_Members_Suggestions $this       Current BP_Members_Suggestions instance.
		 */
		$user_query = apply_filters( 'bp_members_suggestions_query_args', $user_query, $this );
		if ( is_wp_error( $user_query ) ) {
			return $user_query;
		}


		$user_query = new BP_User_Query( $user_query );
		$results    = array();

		foreach ( $user_query->results as $user ) {
			$result          = new stdClass();
			$result->ID      = $user->user_nicename;
			$result->image   = bp_core_fetch_avatar( array( 'html' => false, 'item_id' => $user->ID ) );
			$result->name    = bp_core_get_user_displayname( $user->ID );
			$result->user_id = $user->ID;

			$results[] = $result;
		}

		/**
		 * Filters the members suggestions results.
		 *
		 * @since 2.1.0
		 *
		 * @param array                  $results Array of users to suggest.
		 * @param BP_Members_Suggestions $this    Current BP_Members_Suggestions instance.
		 */
		return apply_filters( 'bp_members_suggestions_get_suggestions', $results, $this );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.