As you may be knowing, BuddyPress does not forces users to create unique group names. If you are the webmaster of a social network, you may not want to allow same group name for multiple groups as it will cause confusions among the users. So, here is a small code snippet to force buddypress to allow creation of unique groups only.
add_filter("groups_group_name_before_save","allow_unique_names_only"); function allow_unique_names_only($name){ global $bp; $groups=BP_Groups_Group::search_groups($name);//search groups $duplicate=false; if('group-details'==$bp->groups->current_create_step&&!empty($groups)&&$groups['total']>0){ //we have match, but is there an exact match foreach($groups['groups'] as $g){ $group=new BP_Groups_Group($g->group_id); if($group->name==$name){ $duplicate=true;//found duplicate break;//break the loop; } } if($duplicate){ bp_core_add_message("A group with this name already exists. Please Choose another name.","error"); bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' ); } } return $name; }
Put the above code in your bp-custom.php and you are good to go. Go ahead and test by creating groups with same name. It will inform you that a group with same exists, please use another name.
Credit: Thanks goes to “gwu” for asking this question in buddydev forum.
I am looking forward to your comments.
If you enjoyed this post, make sure you subscribe to my RSS feed!We will keep coming with more informative tips,tricks,tutorials to keep you updated with wordpress/buddypress/wordpress mu regularly.If you want to help us,You can ,by spreading the words.We provide free and premium plugins/support for wordpress Mu,buddypress at a very low cost (starting with $30 for 3 months membership).If you or anyone you know,needs some real good plugins/themes for their wordpress Mu/buddypress powered site, Please refer them to http://BuddyDev.com.We will highly appreciate your support and keep coming with more useful and free stuffs.

![[blinklist]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/blinklist.png)
![[Bloglines]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/bloglines.png)
![[del.icio.us]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/digg.png)
![[dzone]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/dzone.png)
![[Facebook]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/facebook.png)
![[Ma.gnolia]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/magnolia.png)
![[Mister Wong]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/misterwong.png)
![[Reddit]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/reddit.png)
![[Sphere]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/sphere.png)
![[Sphinn]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/sphinn.png)
![[StumbleUpon]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/technorati.png)
![[Email]](http://www.thinkinginwordpress.com/wp-content/plugins/bookmarkify/email.png)



Neat little tool. Thanks for sharing it, it works well,
Shane.