function user_expire_set_expiration in User Expire 7
Same name and namespace in other branches
- 8 user_expire.module \user_expire_set_expiration()
Set a specific user's expiration time.
Parameters
object $account: A user object to modify.
int $expiration: (Optional) An expiration time to set for the user. If this value is omitted, it will be used to reset a user's expiration time.
5 calls to user_expire_set_expiration()
- UserExpireTestCase::testUserExpire in ./
user_expire.test - user_expire_expire_users in ./
user_expire.module - Expire a group of users.
- user_expire_user_cancel in ./
user_expire.module - Implements hook_user_cancel().
- user_expire_user_delete in ./
user_expire.module - Implements hook_user_delete().
- _user_expire_save in ./
user_expire.module - Save expiration date from user edit form.
1 string reference to 'user_expire_set_expiration'
- user_expire_rules_action_info in ./
user_expire.rules.inc - Implements hook_rules_action_info().
File
- ./
user_expire.module, line 238 - Main module file for User expire module.
Code
function user_expire_set_expiration($account, $expiration = NULL) {
if (!empty($expiration)) {
// If there's an expiration, save it.
db_merge('user_expire')
->key(array(
'uid' => $account->uid,
))
->fields(array(
'uid' => $account->uid,
'expiration' => $expiration,
))
->execute();
$account->expiration = $expiration;
user_expire_notify_user($account);
}
else {
// If the expiration is not set, delete any value that might be set.
if (!isset($account->is_new) || !$account->is_new) {
// New accounts can't have a record to delete.
// Existing records (!is_new) might.
// Remove user expiration times for this user.
$deleted = db_delete('user_expire')
->condition('uid', $account->uid)
->execute();
// Notify user that expiration time has been deleted.
if ($deleted) {
drupal_set_message(t("%name's expiration date has been reset.", array(
'%name' => $account->name,
)));
}
}
}
}