/
/
Auto-join new users to a BuddyPress group

To automatically join new users to an existing group on your BuddyPress site, you will need to add a function to your functions.php file. Add this function, replacing <# group ID #> on line five with the numeric ID of your group.


//Automatically add new users to a group
function automatic_group_membership( $user_id ) {

if( !$user_id ) return false;
groups_accept_invite( $user_id, <# group ID #> );
}
add_action( ‘bp_core_activated_user’, ‘automatic_group_membership’ );

You will need to figure out the group’s numeric ID. Here’s a trick. If you have Firebug installed with Firefox, you can click on your group and then select the group’s avatar within Firebug. It will say the group’s number in the avatar’s image class. It will be something along the lines of: img class=”avatar group-2-avatar”.

11 Responses
  1. Any way to do this based on e-mail?

    e.g. @harvard.edu users are auto-joined to the Harvard Group, @stanford.edu users are auto-joined to Stanford group?

    1. What we want is the user will automatically join a group without having the admin to click a button in the backend

      prosarmientolou
  2. i was wondering if you had a step by step on how to auto but people into groups like what james was talking about based on their email domain?

  3. It would be great to see a small enhancement to this code wherein I join an existing user to a group based on a x-profile field.

Leave a Comment

Your email address will not be published. Required fields are marked *