Skip to content

Instantly share code, notes, and snippets.

@yursil
Created August 18, 2013 15:08
Show Gist options
  • Save yursil/6262120 to your computer and use it in GitHub Desktop.
Save yursil/6262120 to your computer and use it in GitHub Desktop.
Auto enroll into group upon registration for Groups Plugin
// Add Group whenever Admin uses Gravity forms to activate them
add_action('gform_activate_user', 'sm_autogroup');
// And / OR Add Group whenever anyone registers
add_action('user_register', 'sm_autogroup');
function sm_autogroup($user_id)
{
$theUser = get_userdata( $user_id );
if(in_array("therolename",$theUser->roles))
{
$groupToAdd = Groups_Group::read_by_name("thegroupname");
Groups_User_Group::create(array( "user_id" => $user_id, "group_id" => $groupToAdd->group_id ));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment