You are here

function _administerusersbyrole_can_delete_user in Administer Users by Role 6

Same name and namespace in other branches
  1. 5 administerusersbyrole.module \_administerusersbyrole_can_delete_user()
2 calls to _administerusersbyrole_can_delete_user()
administerusersbyrole_form_user_multiple_delete_confirm_alter in ./administerusersbyrole.module
Implements hook_form_FORM_ID_alter().
administerusersbyrole_init in ./administerusersbyrole.module
Implements hook_init().

File

./administerusersbyrole.module, line 99
Non-displayable characters.

Code

function _administerusersbyrole_can_delete_user($account) {
  if ($account->uid == 1) {
    return FALSE;
  }
  if ($account->roles === array(
    DRUPAL_AUTHENTICATED_RID => 'authenticated user',
  )) {
    if (!user_access('delete users with no custom roles')) {
      return FALSE;
    }
  }
  $allow = TRUE;
  foreach ($account->roles as $rid => $role) {
    if ($rid === DRUPAL_AUTHENTICATED_RID) {
      continue;
    }
    if (user_access(_administerusersbyrole_build_perm_string($role, 'delete', TRUE))) {
      return TRUE;
    }
    if (!user_access(_administerusersbyrole_build_perm_string($role, 'delete', FALSE))) {
      $allow = FALSE;
    }
  }
  return $allow;
}