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

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

Is 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:

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

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

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. :)

FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

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:

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.

Tags: