Last active
December 30, 2015 14:09
-
-
Save esafwan/7840669 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment