You are here

function administerusersbyrole_form_user_profile_form_alter in Administer Users by Role 7

Same name and namespace in other branches
  1. 7.2 administerusersbyrole.module \administerusersbyrole_form_user_profile_form_alter()

Implements hook_form_FORM_ID_alter().

Make the user edit form consider our permissions when determining which elements should be visible to administrators.

File

./administerusersbyrole.module, line 146
Provides fine-grained permissions for creating, editing, and deleting users.

Code

function administerusersbyrole_form_user_profile_form_alter(&$form, &$form_state) {
  global $user;
  $account = $form['#user'];
  $register = $form['#user']->uid > 0 ? FALSE : TRUE;
  $admin = _administerusersbyrole_can_edit_user($account);
  $admin = !empty($admin) ? TRUE : user_access('administer users');
  $form['account']['name']['#access'] = $register || $user->uid == $account->uid && user_access('change own username') || $admin;
  $form['account']['status']['#access'] = $account->uid == $user->uid ? $form['account']['status']['#access'] : $admin;
}