You are here

function uc_roles_revoke in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 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.

int $rid: A Drupal role ID.

bool $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 1036
Grants roles upon accepted payment of products.

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_query("SELECT name FROM {role} WHERE rid = :rid", array(
    ':rid' => $rid,
  ))
    ->fetchField();
  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' => theme('username', array(
          'account' => $account,
          'name' => check_plain(format_username($account)),
          'link_path' => 'user/' . $account->uid,
        )),
        '%role' => $role_name,
      )));
    }
  }
}