function user_roles

7.x user.module user_roles($membersonly = FALSE, $permission = NULL)
6.x user.module user_roles($membersonly = FALSE, $permission = NULL)

Retrieve an array of roles matching specified conditions.

Parameters

$membersonly: Set this to TRUE to exclude the 'anonymous' role.

$permission: A string containing a permission. If set, only roles containing that permission are returned.

Return value

An associative array with the role id as the key and the role name as value.

14 calls to user_roles()
blogapi_admin_settings in drupal-6.x/modules/blogapi/blogapi.module
blogapi_metaweblog_new_media_object in drupal-6.x/modules/blogapi/blogapi.module
Blogging API callback. Inserts a file into Drupal.
filter_admin_format_form in drupal-6.x/modules/filter/filter.admin.inc
Generate a filter format form.
filter_admin_format_form_submit in drupal-6.x/modules/filter/filter.admin.inc
Process filter format form submissions.
filter_admin_overview in drupal-6.x/modules/filter/filter.admin.inc
Menu callback; Displays a list of all input formats and which one is the default.

... See full list

File

drupal-6.x/modules/user/user.module, line 1765
Enables the user registration and login system.

Code

function user_roles($membersonly = FALSE, $permission = NULL) {
  // System roles take the first two positions.
  $roles = array(
    DRUPAL_ANONYMOUS_RID => NULL,
    DRUPAL_AUTHENTICATED_RID => NULL,
  );

  if (!empty($permission)) {
    $result = db_query("SELECT r.* FROM {role} r INNER JOIN {permission} p ON r.rid = p.rid WHERE p.perm LIKE '%%%s%%' ORDER BY r.name", $permission);
  }
  else {
    $result = db_query('SELECT * FROM {role} ORDER BY name');
  }

  while ($role = db_fetch_object($result)) {
    switch ($role->rid) {
      // We only translate the built in role names
      case DRUPAL_ANONYMOUS_RID:
        if (!$membersonly) {
          $roles[$role->rid] = t($role->name);
        }
        break;
      case DRUPAL_AUTHENTICATED_RID:
        $roles[$role->rid] = t($role->name);
        break;
      default:
        $roles[$role->rid] = $role->name;
    }
  }

  // Filter to remove unmatched system roles.
  return array_filter($roles);
}