Adding “Unblock the user” option in Views Bulk Operations field

Public

Get raw version
php
  1. /**
  2. * Implements hook_action_info().
  3. */
  4. function mymodule_action_info() {
  5. return array(
  6. 'mymodule_unblock_user_action' => array(
  7. 'label' => t('Unblock the user'),
  8. 'type' => 'user',
  9. 'configurable' => FALSE,
  10. 'triggers' => array('any'),
  11. ),
  12. );
  13. }
  14.  
  15. /**
  16.  * Unblocks a user, defaulting to the current user.
  17.   *
  18.  * @ingroup actions
  19.  */
  20. function mymodule_unblock_user_action($entity, $context = array()) {
  21. // First priority: If there is a $entity->uid, unblock that user.
  22. // This is most likely a user object or the author if a node or comment.
  23. if (isset($entity->uid)) {
  24. $uid = $entity->uid;
  25. }
  26. // Otherwise get user ID from the context.
  27. elseif (isset($context['uid'])) {
  28. $uid = $context['uid'];
  29. }
  30. $account = user_load($uid);
  31. $account = user_save($account, array('status' => 1));
  32. watchdog('action', 'Unblocked user %name.', array('%name' => $account->name));
  33. }