Force BuddyPress to allow unique group names only

Jotted by brajesh on July 3, 2010

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.

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]


WordPress 3.0 and the problem with Mass Updates fail

Jotted by brajesh on July 1, 2010

Have you got the message “Briefly unavailable for scheduled maintenance. Check back in a minute“. Well, It is far too common with wordpress 3.0 if you are using mass updater and if the update fails.

WordPress puts your site to maintinence mode while you use mass updater and if the update fails(or one of the update fails) wordpress does not put back the site to live mode and making everything practically inaccesible

There is an easy workaround.

Check the folder in which wordpress is installed and look for a file called .maintinence. Once you locate it, just delete it and your site will be back to normal.

I believe the mass plugin updater is a welcome addition but leaving the site in maintenance mode when update fails is not a good thing. Anyway, that’s my opinion. What do you think of it? Have you faced the similar problem. If yes, what was your workaround, I would love to hear from you.

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]



Get Adobe Flash playerPlugin by wpburn.com wordpress themes