Programmatically assigning new users to groups I have a specific need where if a user is created and assigned to the role "manager" that user should be automatically subscribed to all groups. I can do this without issues if I hard code the uid. I have problems when i use hook_user_insert and I am not sure why. The problem is that none of my code actually executes. The hook does fire when I load a user object of a hard coded uid however.

Here is my hook:

 function mm_custom_user_insert(&amp;$edit, &amp;$account, $category)
{

    if(in_array('manager', $account-&gt;roles)) {

      //get all gids
      $results = db_query("SELECT gid FROM og");
      $gids= array();
      while($record = $results-&gt;fetchAssoc())
      {
        $gids[]= $record['gid'];
      }

      foreach($gids as $gid)
      {
        og_group($gid, array(
                "entity type"       =&gt; "user",
                "entity"        =&gt; $account,
                "membership type"   =&gt; OG_MEMBERSHIP_TYPE_DEFAULT,
            ));
        og_role_grant($gid, $account-&gt;uid, 3);  

      }
    }
}


My main questions are 
a.) are the user->roles not available at this time? how would I find this out?
b.) could it be that the the uid is not available?

Appreciate the help
The user ID is definitely available, as hook_user_insert() is called after the user data has been committed to the database.

I've just put the following code into a test module called foo:

function foo_user_insert(&amp;$edit, $account, $category) {
  dpm($account);
}


Then I created an account through the admin UI and the output from dpm() looks like this:



So as you can see, the roles are available too.

If you're not familiar with the dpm() function, it's part of the Devel module. It will print any PHP variable to the standard messages area and will display objects/arrays like the screen shot above. It should help you with most of your debugging needs.