function role_expire_user_insert in Role Expire 7
Same name and namespace in other branches
- 8 role_expire.module \role_expire_user_insert()
- 2.x role_expire.module \role_expire_user_insert()
Implements hook_user_insert().
File
- ./
role_expire.module, line 431 - Role Expire module
Code
function role_expire_user_insert(&$edit, $account, $category) {
if ($category == 'account' && (user_access('administer role expire') || user_access('administer users'))) {
// Add roles expiry information for the user role.
foreach (array_keys($edit) as $name) {
if (strpos($name, 'role_expire_') === 0) {
$value = $edit[$name];
$rid = substr($name, strlen('role_expire_'));
// No need to call role_expire_delete_record because it's a new user.
if ($value != '' && array_key_exists($rid, $edit['roles'])) {
$expiry_timestamp = strtotime($value);
role_expire_write_record($account->uid, $rid, $expiry_timestamp);
}
}
}
// Role delegation module adds a separate "roles_change" array to manage
// access. This is merged into the "roles" array prior to saving.
$roles_key = module_exists('role_delegation') && !user_access('administer permissions') ? 'roles_change' : 'roles';
if (isset($edit[$roles_key])) {
// Add default expiration to any new roles that have been given to the user.
if ($roles_key == 'roles' && isset($edit['original'])) {
$new_roles = array_diff(array_keys($edit[$roles_key]), array_keys($edit['original']->roles));
}
else {
$new_roles = array_filter($edit[$roles_key]);
}
if (isset($new_roles)) {
// We have the new roles, loop over them and see whether we need to assign expiry to them.
foreach (array_keys($edit[$roles_key]) as $role_id) {
role_expire_process_default_role_duration_for_user($role_id, $account->uid);
}
}
}
// if edit[roles] or edit[roles_change]
}
// if category && user_access
}