bp_friends_prime_mentions_results()

Used by the Activity component’s @mentions to print a JSON list of the current user’s friends.


Description Description

This is intended to speed up @mentions lookups for a majority of use cases.

See also See also


Top ↑

Source Source

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

function bp_friends_prime_mentions_results() {

	// Stop here if user is not logged in.
	if ( ! is_user_logged_in() ) {
		return;
	}

	if ( ! bp_activity_maybe_load_mentions_scripts() ) {
		return;
	}

	// Bail out if the site has a ton of users.
	if ( bp_is_large_install() ) {
		return;
	}

	if ( friends_get_total_friend_count( get_current_user_id() ) > 30 ) {
		return;
	}

	$friends_query = array(
		'count_total'     => '',                    // Prevents total count.
		'populate_extras' => false,

		'type'            => 'alphabetical',
		'user_id'         => get_current_user_id(),
	);

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

	foreach ( $friends_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 ) );

		if ( ! empty( $user->display_name ) && ! bp_disable_profile_sync() ) {
			$result->name = $user->display_name;
		} else {
			$result->name = bp_core_get_user_displayname( $user->ID );
		}

		$results[] = $result;
	}

	wp_localize_script( 'bp-mentions', 'BP_Suggestions', array(
		'friends' => $results,
	) );
}

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.