How do I add a user to a group?
For D7 its

$account = user_load($uid);
$group = group_load($group_id);
$group-&gt;addMember($account-&gt;uid, array('joined_on' =&gt; REQUEST_TIME));


To delete

$group-&gt;removeMember($account-&gt;uid);


To request

$group-&gt;addMember($account-&gt;uid, array('status' =&gt; 'requested', 'requested_on' =&gt; REQUEST_TIME));


To block:

foreach (group_membership_load_by_user($account-&gt;uid) as $group_membership) {
  $block_gid = // some code to get the Group ID that you want the ...
               // ... the block to take place in.
  $gid = $group_membership-&gt;gid;
  if ($gid == $block_gid) {
    global $user;
    if ($group_membership-&gt;status != 'blocked') {
      $group_membership-&gt;blocked_status = $group_membership-&gt;status;
      $group_membership-&gt;status = 'blocked';
      $group_membership-&gt;blocked_on = REQUEST_TIME;
      $group_membership-&gt;blocked_by = $user-&gt;uid;
      $group_membership-&gt;save();
    }
}


To Unblock:

foreach (group_membership_load_by_user($account-&gt;uid) as $group_membership) {
    $unblock_gid = // some code to get the Group ID that you want the ...
                  // ... the unblock to take place in.
    $gid = $group_membership-&gt;gid;
    if ($gid == $unblock_gid) {
      if ($group_membership-&gt;status == 'blocked') {
        $group_membership-&gt;status = $group_membership-&gt;blocked_status;
        $group_membership-&gt;blocked_status = '';
        $group_membership-&gt;blocked_on = NULL;
        $group_membership-&gt;blocked_by = NULL;
        $group_membership-&gt;save();
      }
    }
}