How to restrict group creation to certain users
-
Hi all,
This “trick” is intended to allow certain WP user roles (like Admin or Subscriber) to create groups while preventing the rest, and it is intended for installations based in WP4.5 and BP2.5.2. I cannot assure it works for other versions.
NOTE: As a BP plugin file will be modified, the trick will not survive BP updates.
1) Make sure that users cannot create groups by default (Settings -> BuddyPress -> Options).
2) Choose the users that you want to enable (to create groups). Get the list of WP capabilities for each of them from here (or use a role/capability editing plugin):
https://codex.wordpress.org/Roles_and_Capabilities
Choose one capability which is only shared by those users that will have the ability to create groups.
For example, if you want WP roles Contributor, Author, Editor and Admin to have the ability to create groups but you want to exclude Subscribers, then choose “delete_posts” or “edit_posts” as your differentiating capability (they all -but Subscriber- can “delete_posts”).
Combinations of custom Roles and Capabilities also work. In my case, I am using s2member Roles and Capabilities (i.e. “access_s2member_level2”).
The choosen capability will be called my_choosen_capability beyond this point.
3) Then, edit /path/to/your/installation/wp-content/plugins/buddypress/bp-groups/bp-groups-template.php. In line 4312 you will find the following function:
function bp_user_can_create_groups()
After the if structure that enables Admins to create groups regardless the settings, add this:
if(current_user_can('my_choosen_capability')){
return true;
}
In my case as my_choosen_capability = access_s2member_level2, the code looks like this:
if(current_user_can('access_s2member_level2')){
return true;
}
Then save and enjoy till next update.
4) When the enabled users visit the group page, two buttons will be printed:
-Join group
-Create groupThis is it. Have fun!
- You must be logged in to reply to this topic.