function user_block_user_action

You are here

7 user.module user_block_user_action(&$entity, $context = array())
6 user.module user_block_user_action(&$object, $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

4 string references to 'user_block_user_action'
drupal-6.bare.database.php in modules/simpletest/tests/upgrade/drupal-6.bare.database.php
Bare installation of Drupal 6.17, for test purposes.
drupal-6.filled.database.php in modules/simpletest/tests/upgrade/drupal-6.filled.database.php
Filled installation of Drupal 6.17, for test purposes.
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 3692
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));
}

Comments

The description of this function should really be changed from

Blocks the current user.

to

Blocks a user.

since it can be used to either block the current user OR some other user depending upon the parameters passed in.

It's description is confusing and scares people away from using it in VBO actions because they assume it means it only works to block the currently logged in user using the VBO--not the results from the VBO View.