function role_expire_user_update in Role Expire 7
Implements hook_user_update().
File
- ./
role_expire.module, line 389 - Role Expire module
Code
function role_expire_user_update(&$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_'));
if ($value != '' && array_key_exists($rid, $edit['roles'])) {
$expiry_timestamp = strtotime($value);
role_expire_write_record($account->uid, $rid, $expiry_timestamp);
}
else {
role_expire_delete_record($account->uid, $rid);
}
}
}
if (isset($edit['roles'])) {
// Add default expiration to any new roles that have been given to the user.
$new_roles = array_diff(array_keys($edit['roles']), array_keys($edit['original']->roles));
if (isset($new_roles)) {
// We have the new roles, loop over them and see whether we need to assign expiry to them.
foreach ($new_roles as $role_id) {
role_expire_process_default_role_duration_for_user($role_id, $account->uid);
}
}
// Remove expiration for roles that have been removed from the user.
$del_roles = array_diff(array_keys($edit['original']->roles), array_keys($edit['roles']));
if (isset($del_roles)) {
// We have the deleted roles, loop over them and remove their expiry info.
foreach ($del_roles as $role_id) {
role_expire_delete_record($account->uid, $role_id);
}
}
}
// if edit[roles]
}
// if category && user_access
}