You are here

function user_block_user_action in Drupal 7

Same name and namespace in other branches
  1. 6 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 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 3771
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,
  ));
}