Code to add 'Unblock the user' option in Views Bulk Operations field.

Public

thanks to http://www.tekritisoftware.com/add-unblock-user-option-views-bulk-operat...

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