How To Restrict BuddyPress Group Creation Based on User Roles and Capabilities

restrictedIs your BuddyPress group creation getting out of hand? Would you rather your users submit group requests to you for moderation and create them yourself? After doing a little bit of hunting on the BuddyPress forums, I stumbled across this custom plugin created by Simon Wheatley.

Here’s how you can use it to restrict BuddyPress group creation to admin only:

Step 1: Download the Restrict Group Creation plugin.

Step 2: FTP that file to your Plugins directory and activate. This will change it so that no users can create groups.

Step. 3: Add this code to each function to permit the admin to create groups:

1
2
if ( current_user_can( 'manage_options' ) )
return true;

So what’ you’ll have then for the first function will look something like this:

1
2
3
4
5
6
7
8
9
function rgc_validate_creation( $allowed, $group_details ) {
	// At this point one could check the capabilities of the user, the details of the
	// group to be created, etc.
	if ( current_user_can( 'manage_options' ) )
return true;
	bp_core_add_message( 'Sorry, you are not allowed to create groups.', 'error' );
	return false;
}
add_filter( 'bp_allow_create_group', 'rgc_validate_creation', null, 2 );

You’ll want to modify the other functions in that plugin to match – or you can download my modified version here. :)

You can also modify it so that other roles can create groups as well, based on their roles and capabilities. For example, if I wanted to make it so that only Admins and Editors are allowed to create groups, I might use:

1
2
if ( current_user_can( 'delete_others_posts' ) )
return true;

This offers you a great deal of flexibility in customizing group creation by checking the user’s capabilities. I hope this is helpful to those wanting to further customize their BuddyPress communities.