Same name and namespace in other branches
  1. 6.x modules/user/user.module \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.
2 string references to 'user_block_user_action'
TriggerUserActionTestCase::testUserActionAssignmentExecution in modules/trigger/trigger.test
Tests user action assignment and execution.
user_action_info in modules/user/user.module
Implements hook_action_info().

File

modules/user/user.module, line 3791
Enables the user registration and login system.

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,
  ));
}