Hope this will help you,
In Drupal 7, after user registration form submit you can create the group.
For this example I'm using hook_form_FORM_ID_alter
/**
* Implement hook_form_user_register_form_alter().
*/
function test_form_user_register_form_alter(&$form, &$form_state) {
$form['#submit'][] = 'create_group_on_user_registration';
}
/**
* Custom submit function for user registration form
*/
function create_group_on_user_registration($form, &$form_state) {
$usr_obj = $form_state['user']; //get registered user object
if (is_object($usr_obj) && isset($usr_obj->uid) && (your_conditions)) {// dont forget to add your conditions
$bodytext = "group body";
$author_id = 1;//you can change author id, i'm making admin as author
$node = new stdClass(); // Create a new node object
$node->type = "groups"; // Group content type
node_object_prepare($node); // Set some default values
$node->title = "group title2";
$node->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
//for author id I have given admin, you can give any other user id,
//but that user should have permission to create group cotent type
$node->uid = $author_id; // UID of the author of the node; or use $node->name
$node->body[$node->language][0]['value'] = $bodytext;
$node->body[$node->language][0]['summary'] = text_summary($bodytext);
$node->body[$node->language][0]['format'] = 'filtered_html';
if ($node = node_submit($node)) { // Prepare node for saving
node_save($node);//$node->nid will have node id
}
}
}
NOTE :
- Go through all comments
- Make changes as per your requirements