BP_Friends_Friendship::total_friend_count( int $user_id )
Get a total friend count for a given user.
Description
Parameters
- $user_id
-
(int) (Optional) ID of the user whose friendships you are counting. Default: displayed user (if any), otherwise logged-in user.
Return
(int) Connection count for the user.
Source
File: bp-friends/classes/class-bp-friends-friendship.php
public static function total_friend_count( $user_id = 0 ) { global $wpdb; if ( empty( $user_id ) ) { $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); } /* * This is stored in 'total_friend_count' usermeta. * This function will recalculate, update and return. */ $args = array( 'is_confirmed' => 1, ); $friendships = self::get_friendships( $user_id, $args ); $count = count( $friendships ); // Do not update meta if user has never had friends. if ( ! $count && ! bp_get_user_meta( $user_id, 'total_friend_count', true ) ) { return 0; } bp_update_user_meta( $user_id, 'total_friend_count', (int) $count ); return absint( $count ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.0.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.