BuddyPress Limit Friendship plugin allows site owners to limit the number of friends a user can have on their network. It does so based on the 2 criteria.
The criteria are:-
- Number of Existing Friends
- Number of Existing Friends + Number of Pending Friendship Request Sent & Received
When you select the criteria as No. of existing Friends, The plugin only checks for existing friends count(for both the users) and will limit the user to be added as friend or to add a new friend if they have
When you select the criteria as No. Of existing Friends + Friendship Requests, the plugin will check for both the users that they don't have crossed the limit(The sum of Friendship Requests sent, which is pending; The friendship requests received which is not approved and the total no. of exiting friends is less than the allowed limit for both the users).
This plugin is also compatible with our Extended Friendship request plugin.
Here is an example of what happens when a user tries to add new friend.
The best use case will be to use this plugin in a membership based site and ask users to upgrade account for more friends or to use it as a tool for spam control(Do not allow too many friends quickly).
For now, I have allowed users to accept any pending request they already have even if the limit is over. Please do let me know if you want that and I will include it.
Customizing Allowed Friendship Count based on WordPress Roles:-
You can use the following code to add custom limit based on roles/capabilities
/** * Limit BuddyPress friendship based on WordPress roles * * @param int $count how many * @param int $user_id for the given user. * * @return int allowed no. of friends */ function buddydev_limit_friendship_count_based_on_role( $count, $user_id ) { if ( user_can( $user_id, 'manage_options' ) ) { //site admin $count = 100; // 100 friends allowed } elseif ( user_can( $user_id, 'moderate_comments' ) ) { //editor } elseif ( user_can( $user_id, 'edit_published_posts' ) ) { //authors } elseif ( user_can( $user_id, 'read' ) ) { //subscriber $count = 3; // only 3 allowed for subscribers } return $count; } add_filter( 'bp_limit_friendship_count', 'buddydev_limit_friendship_count_based_on_role', 10, 2 );
Please put the code in bp-custom.php to make it work. You can also customize the limit based on BuddyPress member types.