function user_roles

cis7 user.module user_roles($membersonly = FALSE, $permission = NULL)
cle7 user.module user_roles($membersonly = FALSE, $permission = NULL)
elmsmedia7 user.module user_roles($membersonly = FALSE, $permission = NULL)
icor7 user.module user_roles($membersonly = FALSE, $permission = NULL)
meedjum_blog7 user.module user_roles($membersonly = FALSE, $permission = NULL)
mooc7 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.

51 calls to user_roles()
alpha_theme_settings_general in sites/all/themes/ulmus/omega/alpha/includes/theme-settings-general.inc
@todo
better_formats_get_formats_per_role in sites/all/modules/ulmus/better_formats/better_formats.admin_defaults.inc
Retrieve the formats available to users by role.
block_admin_configure in modules/block/block.admin.inc
Form constructor for the block configuration form.
cis_service_activation_codes_admin_settings in sites/all/modules/elmsln_contrib/cis_connector/modules/cis_service_activation_codes/cis_service_activation_codes.admin.inc
@file Admin page callbacks for the cis_service_activation_codes module.
context_condition_user::condition_values in sites/all/modules/ulmus/context/plugins/context_condition_user.inc
Condition values.

... See full list

1 string reference to 'user_roles'
og_views_data_alter in sites/all/modules/ulmus/og/includes/views/og.views.inc
Implements hook_views_data_alter().

File

modules/user/user.module, line 2871
Enables the user registration and login system.

Code

function user_roles($membersonly = FALSE, $permission = NULL) {
  $query = db_select('role', 'r');
  $query->addTag('translatable');
  $query->fields('r', array('rid', 'name'));
  $query->orderBy('weight');
  $query->orderBy('name');
  if (!empty($permission)) {
    $query->innerJoin('role_permission', 'p', 'r.rid = p.rid');
    $query->condition('p.permission', $permission);
  }
  $result = $query->execute();

  $roles = array();
  foreach ($result as $role) {
    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;
    }
  }

  return $roles;
}