Programmatically import users and create each for them organic groups I have a function that allows me to create users from the data of an external database:

  function _loginuser_authenticate_validate($form, &amp;$form_state) {
    global $user;

    // Use external database.
    db_set_active('external_database');
    // … 
  }


Now I want to create, for each user from the external database, two groups (each group with four Drupal users, a group administrator, and three normal members).
I can create a group with og_insert_group($node);.
I can also create an admin for this group with og_save_subscription($node-&gt;nest, $node-&gt;uid, array ('is_active' =&gt; 1, 'is_admin' =&gt; 1));.

I don't know how to create multiple groups, and add members to these groups.
I also do not know where to put the code to create groups in the LoginUser module, or in another module.
Your explanation seems a little bit confused. Creation of an OG is as simply as creating a node.

So from what I understood you wish :


Get a user data from external source (how you perform this ? by cron ?)
Create a group for each user
Assign that user as group admin ?


Is it what you want to perform ?

Also take a look here :

http://drupalcontrib.org/api/drupal/contributions%21og%21og.module/7