function rules_user in Rules 6
Implementation of hook_user().
Related topics
File
- rules/
modules/ rules.events.inc, line 27 - Invokes events for supported modules. Usually this should be directly in the module providing rules integration instead.
Code
function rules_user($op, &$edit, &$account, $category = NULL) {
static $account_unchanged;
// We don't support updates for other categories than 'account'
if ($op == 'update' && $category == 'account') {
// Save the unchanged account for the use with op after_update.
$account_unchanged = drupal_clone($account);
}
else {
if ($op == 'after_update' && $category == 'account') {
rules_invoke_event('user_update', array(
'account' => &$account,
'account_unchanged' => $account_unchanged,
));
}
else {
if (in_array($op, array(
'insert',
'login',
'logout',
'view',
'delete',
))) {
// At user creation add the assigned roles which are not available in
// $account yet to $account, so rules is aware of them.
if ($op == 'insert' && isset($edit['roles'])) {
$system_roles = user_roles();
foreach ($edit['roles'] as $role_id => $value) {
if (isset($system_roles[$role_id])) {
$account->roles[$role_id] = $system_roles[$role_id];
}
}
}
rules_invoke_event('user_' . $op, array(
'account' => &$account,
));
// Allow adding user roles during registration.
if ($op == 'insert' && isset($account->roles)) {
$edit += array(
'roles' => array(),
);
$edit['roles'] += $account->roles;
}
}
}
}
}