You should write a custom module that implements hook_form_alter().
Get the $form_id
of the 'create new user' form that you want to alter.
( drupal_set_message($form_id);
is an easy way to do this. )
Add a custom submit handler to the 'create user' form that uses the respective details and the og_group() function to add the new user to the group.
function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
if (isset($form_id) && $form_id == 'YOUROG_USERCREATION_FORMID') {
$form['#submit'][] = 'MODULENAME_submit_handler';
}
}
function MODULENAME_submit_handler($form, &$form_state) {
$gid = $form_state['values']['groupID'];
$uid = $form_state['values']['userID'];
$account = user_load($uid);
$values = array(
'entity_type' => 'user',
'entity' => $account,
'state' => OG_STATE_ACTIVE,
);
og_group('node', $gid, $values);
return $form;
}
Just as a point of information, this code sample is geared towards OG 7.2.x.
If you're using OG 7.1.x, you drop the first argument in og_group, so it would be og_group($gid, $values);
Also, the possible $values
you can use, and defaults, are as follows:
# taken directly from og.module
$values += array(
'entity type' => 'user',
'entity' => FALSE,
'state' => OG_STATE_ACTIVE,
'save' => TRUE,
'force reload' => TRUE,
'membership type' => OG_MEMBERSHIP_TYPE_DEFAULT,
'membership fields' => array(),
'created' => time(),
);