1 user.actions.inc | user_block_user_action(User $account, &$context) |
Blocks a specific user account.
Parameters
User $account: The user entity whose account will be blocked.
Related topics
File
- core/
modules/ user/ user.actions.inc, line 15 - Action callbacks for User module.
Code
function user_block_user_action(User $account, &$context) {
global $user;
// Don't block User 1, or the user performing the action.
if ($account->uid === '1') {
backdrop_set_message(t('The user account %admin_name (user with ID 1) cannot be blocked.', array('%admin_name' => $account->name)), 'warning');
return FALSE;
}
elseif ($account->uid == $user->uid) {
backdrop_set_message(t('You cannot block your own user account.'), 'warning');
return FALSE;
}
if ($account->status == 1) {
$account->status = 0;
$account->save();
}
}