Limiting Group Invite Request to group Admins Only
A couple of days ago, Phillip asked me this question. He wanted to limit the group invites to group admins only. The goal was to stop the group members other than the group admin to send the invitation request for the group.
I thought this might be useful for some of you, so here I am sharing it.
It is a simple tutorial and will take just 5 minutes.
Goals:-
- Allow only the Group Admin to send the invitation request for group
- Stop normal group members from Sending the invitation request
So, the simple way to accomplish this was to hide the send invites tab on individual group.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | function bpdev_limit_group_invites( $can_invite, $group_id, $invite_status ) { // if the user is not logged in, do not show. if ( ! is_user_logged_in() ) { return false; } // if the current user is Site Admin, do not restrict. if ( is_super_admin() ) { return true; } // otherwise, let us check for the user role in the group. $user_id = get_current_user_id(); if ( groups_is_user_admin( $user_id, $group_id ) ) { return true; } return false; } add_filter( 'bp_groups_user_can_send_invites', 'bpdev_limit_group_invites', 10, 3 ); |
You can even modify this code to allow group admins/group moderators by changing this line
1 2 3 | if ( groups_is_user_admin( $user_id, $group_id ) ) { return true; } |
to
1 2 3 | if ( groups_is_user_admin( $user_id, $group_id ) || groups_is_user_mod( $user_id, $group_id ) ) { return true; } |
Here is a screenshot of what a normal member sees:-
The code should go to the bp-custom.php
Hope that it helps some of you 🙂
Please do let me know if you use it, whether it works for you or not?