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(&$edit, &$account, $category)
{
if(in_array('manager', $account->roles)) {
//get all gids
$results = db_query("SELECT gid FROM og");
$gids= array();
while($record = $results->fetchAssoc())
{
$gids[]= $record['gid'];
}
foreach($gids as $gid)
{
og_group($gid, array(
"entity type" => "user",
"entity" => $account,
"membership type" => OG_MEMBERSHIP_TYPE_DEFAULT,
));
og_role_grant($gid, $account->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