bp_friends_prime_mentions_results()
Used by the Activity component’s @mentions to print a JSON list of the current user’s friends.
Description
This is intended to speed up @mentions lookups for a majority of use cases.
See also
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 = get_user_meta( $user->ID, 'nickname', true ) ?: $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 = bp_custom_display_name_format( $user->display_name, $user->ID ); } else { $result->name = bp_core_get_user_displayname( $user->ID ); } $results[] = $result; } wp_localize_script( 'bp-mentions', 'BP_Suggestions', array( 'friends' => $results, ) ); }
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.