esafwan
12/7/2013 - 12:34 PM

Add unblock user to Views Bulk Operation of User. By default only block user exist. It is possible via "Modify entity values" but its confus

Add unblock user to Views Bulk Operation of User. By default only block user exist. It is possible via "Modify entity values" but its confusing to most. And includes one additional step.

<?php

/* Unblock user in bulk operations
 * Implements hook_action_info().
*/
function unblock_user_action_info() {
    return array(
    'unblock_user_unblock_action' => array(
    'label' => t('Unblock the user'),
    'type' => 'user',
    'configurable' => FALSE,
    'triggers' => array('any'),
    ),
    );
}

/* Unblocks a user, defaulting to the current user.
 * @ingroup actions
*/
function unblock_user_unblock_action(&$entity, $context = array()) {
      // First priority: If there is a $entity->uid, unblock that user.
      // This is most likely a user object or the author if a node or comment.
      if (isset($entity->uid)) {
      $uid = $entity->uid;
      }
      // Otherwise get user ID from the context.
      elseif (isset($context['uid'])) {
      $uid = $context['uid'];
      }
      $account = user_load($uid);
      $account = user_save($account, array('status' => 1));
      //Log the change using watchdog.
      watchdog('action', 'Unblocked user %name.', array('%name' => $account->name));
}