Hi,
Can anyone tel me how to have unique group names, same functionality as the username ?
May be even prompt user with error message saying group by this name already exists.
Thanks
Hi,
Can anyone tel me how to have unique group names, same functionality as the username ?
May be even prompt user with error message saying group by this name already exists.
Thanks
It can be done via hooking on the filter
"groups_group_name_before_save" but there is no other way to do it
Put this function in your theme's functions.php
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("Duplicate group name","error");
bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
}
}
return $name;
}
and then try creating duplicate group.
Please let me know if it works for you or not ?
I tried it. it worked for me. thanks :)
too good. Just copy paste and it works.
Thanks
@brajesh
Thanks for this. Brilliantly simple as always :-)
You must log in to post.