Helping you Build Your Own Social Network!

Faster, better and easier!

unique group names

(5 posts) (4 voices)

Tags:

No tags yet.


  1. 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

    Posted 1 year ago #
  2. 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 ?

    Posted 1 year ago #
  3. I tried it. it worked for me. thanks :)

    Posted 1 year ago #
  4. too good. Just copy paste and it works.

    Thanks

    Posted 1 year ago #
  5. @brajesh

    Thanks for this. Brilliantly simple as always :-)

    Posted 1 year ago #

Reply

You must log in to post.