@reddyink, Well, it might not be the way you are SUPPOSED to do it, but this is how I do it in a lot of my modifications:
PHP Code:
// initialize data manger
require_once(DIR . '/includes/class_dm.php');
require_once(DIR . '/includes/class_dm_user.php');
require_once(DIR . '/includes/functions_ranks.php');
$userdm =& datamanager_init('User', $vbulletin, ERRTYPE_CP);
// Get User Info
$user = fetch_userinfo($userid);
// Get current User Groups
$groups = $user['membergroupids'];
// If the member is NOT part of the groups you want to add, then add those values to $groups
if (!in_array($new_group_1, $groups)) {$groups[] = $new_group_1;}
if (!in_array($new_group_2, $groups)) {$groups[] = $new_group_2;}
if (!in_array($new_group_3, $groups)) {$groups[] = $new_group_3;}
// Set the user data to a datamanager
$userdm->set_existing($user);
// If the new groups could change the user's "rank" somehow, be sure to get the user's new "rank" (have to set the new groups to the $user info first)
$user['membergroupids'] = implode(',',$groups);
$userrank =& fetch_rank($user);
// Set the new user groups
$userdm->set('membergroupids', $user['membergroupids']);
// Set the user rank, if applicable
$userdm->setr('rank', $userrank);
// Save the data
$userdm->save();