function regcode_roles_regcode_used in Registration codes 6
Same name and namespace in other branches
- 6.2 regcode_roles/regcode_roles.module \regcode_roles_regcode_used()
- 7.2 regcode_roles/regcode_roles.module \regcode_roles_regcode_used()
- 7 regcode_roles/regcode_roles.module \regcode_roles_regcode_used()
Implements hook_regcode_used()
Add the new role to the user
File
- regcode_roles/
regcode_roles.module, line 244
Code
function regcode_roles_regcode_used(&$edit, &$account, $regcode) {
// Do nothing if the regcode is not valid
if (!is_array($regcode)) {
return;
}
// Grab applicable roles for category used
$rules = regcode_roles_get_rules($regcode['category']);
// Apply the rules
if (count($rules)) {
if (!is_array($edit['roles'])) {
$edit['roles'] = array();
}
foreach ($rules as $rule) {
$edit['roles'][$rule['rid']] = $rule['role'];
}
}
// Apply role_expire rules
if (module_exists('role_expire')) {
foreach ($rules as $rule) {
if ($rule['expire_date']) {
$expiry_timestamp = $rule['expire_date'];
}
elseif ($rule['expire_duration']) {
$expiry_timestamp = time() + $rule['expire_duration'] * 60 * 60 * 24;
}
role_expire_write_record($account->uid, $rule['rid'], $expiry_timestamp);
}
}
}