modemlooper avatar
About Blog

BuddyPress Force Group Type

1 min read
buddypress wordpress php

Some BuddyPress sites allow users to create groups but might want them all private or all public.

// blocks changing group type on edit screen
function bp_block_private_groups_edit( $status ) {

	//no restriction to site admin
	if ( !is_super_admin() ) {
		$status = array( 'public' );
	}

	return $status;
	
}
add_filter( 'groups_allowed_status', 'bp_block_private_groups_edit' );

// blocks changing group type on group creation
function bp_block_private_groups_create( $group_id ) {
 
	//no restriction to site admin
	if ( !bp_is_group_create() || is_super_admin() )
			return false;
	
	if ( !current_user_can('manage_options') ) {
		groups_edit_group_settings( $group_id, $enable_forum, 'public', $invite_status );
	}
	
}
add_action( 'groups_group_create_complete',  'bp_block_private_groups_create' );
add_action( 'groups_created_group',  'bp_block_private_groups_create' );