| Versions | |
|---|---|
| 7 | action_example_unblock_user_action(&$entity, $context = array()) |
Unblock an user. This action can be fired from different trigger types:
$entity An optional user object (could be a user, or an author if context is node or comment)
array $context Array with parameters for this action: depends on the trigger. The context is not used in this example.
examples/
<?php
function action_example_unblock_user_action(&$entity, $context = array()) {
// First we check that entity is a user object. If this is the case, then this
// is a user-type trigger.
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' => 1));
watchdog('action_example', 'Unblocked user %name.', array('%name' => $account->name));
drupal_set_message(t('Unblocked user %name', array('%name' => $account->name)));
}
?>