function uc_roles_revoke in Ubercart 6.2
Same name and namespace in other branches
- 7.3 uc_roles/uc_roles.module \uc_roles_revoke()
 
Revokes a role on a given user.
This function deletes a given role from a user's list of roles, as well as removing any expiration data associated with the user/role. The function notifies the user of revocation.
Parameters
$account: A Drupal user object.
$rid: A Drupal role ID.
$silent: When set to TRUE will suppress any Drupal messages from this function.
1 call to uc_roles_revoke()
- uc_roles_cron in uc_roles/
uc_roles.module  - Implements hook_cron().
 
File
- uc_roles/
uc_roles.module, line 1188  
Code
function uc_roles_revoke(&$account, $rid, $silent = FALSE) {
  global $user;
  // Remove this role from the user's list.
  $roles_list = $account->roles;
  unset($roles_list[$rid]);
  $account = user_save($account, array(
    'roles' => $roles_list,
  ));
  // Remove our record of the expiration.
  uc_roles_delete($account, $rid, $silent);
  $role_name = db_result(db_query('SELECT name FROM {role} WHERE rid = %d', $rid));
  if (!$silent) {
    if ($user->uid == $account->uid) {
      drupal_set_message(t('Your %role role has been revoked.', array(
        '%role' => $role_name,
      )));
    }
    else {
      drupal_set_message(t('%user has had the %role role revoked.', array(
        '%user' => $account->name,
        '%role' => $role_name,
      )));
    }
  }
}