user_roles

  1. drupal
    1. 4.7
    2. 5 user.module
    3. 6 user.module
    4. 7 user.module
Versions
4.7 – 5 user_roles($membersonly = 0, $permission = 0)
6 – 7 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.

▾ 6 functions call user_roles()

filter_admin_format_form in modules/filter.module
Generate a filter format form.
filter_admin_format_form_submit in modules/filter.module
Process filter format form submissions.
filter_admin_overview in modules/filter.module
Displays a list of all input formats and which one is the default
theme_user_admin_new_role in modules/user.module
upload_settings in modules/upload.module
user_edit_form in modules/user.module

Code

modules/user.module, line 1730

<?php
function user_roles($membersonly = 0, $permission = 0) {
  $roles = array();

  if ($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)) {
    if (!$membersonly || ($membersonly && $role->rid != DRUPAL_ANONYMOUS_RID)) {
      $roles[$role->rid] = $role->name;
    }
  }
  return $roles;
}
?>