friends_get_friends_invite_list( int $user_id, int $group_id )
Get a list of friends that a user can invite into this group.
Description
Excludes friends that are already in the group, and banned friends if the user is not a group admin.
Parameters
- $user_id
-
(int) (Required) User ID whose friends to see can be invited. Default: ID of the logged-in user.
- $group_id
-
(int) (Required) Group to check possible invitations against.
Return
(mixed) False if no friends, array of users if friends.
Source
File: bp-friends/bp-friends-functions.php
function friends_get_friends_invite_list( $user_id = 0, $group_id = 0 ) { // Default to logged in user id. if ( empty( $user_id ) ) $user_id = bp_loggedin_user_id(); // Only group admins can invited previously banned users. $user_is_admin = (bool) groups_is_user_admin( $user_id, $group_id ); // Assume no friends. $friends = array(); /** * Filters default arguments for list of friends a user can invite into this group. * * @since BuddyPress 1.5.4 * * @param array $value Array of default parameters for invite list. */ $args = apply_filters( 'bp_friends_pre_get_invite_list', array( 'user_id' => $user_id, 'type' => 'alphabetical', 'per_page' => 0 ) ); // User has friends. if ( bp_has_members( $args ) ) { /** * Loop through all friends and try to add them to the invitation list. * * Exclude friends that: * 1. are already members of the group * 2. are banned from this group if the current user is also not a * group admin. */ while ( bp_members() ) : // Load the member. bp_the_member(); // Get the user ID of the friend. $friend_user_id = bp_get_member_user_id(); // Skip friend if already in the group. if ( groups_is_user_member( $friend_user_id, $group_id ) ) continue; // Skip friend if not group admin and user banned from group. if ( ( false === $user_is_admin ) && groups_is_user_banned( $friend_user_id, $group_id ) ) continue; // Friend is safe, so add it to the array of possible friends. $friends[] = array( 'id' => $friend_user_id, 'full_name' => bp_get_member_name() ); endwhile; } // If no friends, explicitly set to false. if ( empty( $friends ) ) $friends = false; /** * Filters the list of potential friends that can be invited to this group. * * @since BuddyPress 1.5.4 * * @param array|bool $friends Array friends available to invite or false for no friends. * @param int $user_id ID of the user checked for who they can invite. * @param int $group_id ID of the group being checked on. */ return apply_filters( 'bp_friends_get_invite_list', $friends, $user_id, $group_id ); }
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.