function user_block_user_action
Blocks a specific user or the current user, if one is not specified.
Parameters
$entity: (optional) An entity object; if it is provided and it has a uid property, the user with that ID is blocked.
$context: (optional) An associative array; if no user ID is found in $entity, the 'uid' element of this array determines the user to block.
Related topics
1 call to user_block_user_action()
- UserActionsTest::testUserBlockUnBlockActions in modules/
user/ user.test - Tests user block and unblock actions.
1 string reference to 'user_block_user_action'
- TriggerUserActionTestCase::testUserActionAssignmentExecution in modules/
trigger/ trigger.test - Tests user action assignment and execution.
File
-
modules/
user/ user.module, line 3795
Code
function user_block_user_action(&$entity, $context = array()) {
// First priority: If there is a $entity->uid, block that user.
// This is most likely a user object or the author if a node or comment.
if (isset($entity->uid)) {
$uid = $entity->uid;
}
elseif (isset($context['uid'])) {
$uid = $context['uid'];
}
else {
$uid = $GLOBALS['user']->uid;
}
$account = user_load($uid);
$account = user_save($account, array(
'status' => 0,
));
watchdog('action', 'Blocked user %name.', array(
'%name' => $account->name,
));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.