function user_block_user_action

user_block_user_action(&$entity, $context = array())

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

File

modules/user/user.module, line 3747
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'];
  }
  // If neither of those are valid, then block the current user.
  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));
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!user!user.module/function/user_block_user_action/7.x