function userprotect_get_user_protection in User protect 6
Same name and namespace in other branches
- 5 userprotect.module \userprotect_get_user_protection()
- 7 userprotect.module \userprotect_get_user_protection()
Checks to see if the specified user has the specified protection.
Parameters
$account The user object to check.:
$protection The protection to check for.:
Return value
TRUE if the user has the specified protection, FALSE otherwise.
4 calls to userprotect_get_user_protection()
- userprotect_form_alter in ./
userprotect.module - Alters forms for user protection.
- userprotect_user_admin_account_validate in ./
userprotect.module - Custom validation function for protecting users from the user administration operations.
- userprotect_user_delete_access in ./
userprotect.module - Access callback for user delete pages.
- userprotect_user_edit_access in ./
userprotect.module - Access callback for user edit pages.
File
- ./
userprotect.module, line 1130
Code
function userprotect_get_user_protection($account, $protection) {
global $user;
static $protections = array();
static $role_protections;
$uid = $account->uid;
$roles = $account->roles;
// Users editing their own accounts have the permissions for e-mail
// and password determined by the role-based setting in the userprotect
// section at admin/user/access. This is done for consistency with the
// way core handles the self-editing of usernames.
if ($uid == $user->uid && in_array($protection, array(
'up_name',
'up_mail',
'up_pass',
'up_openid',
'up_edit',
))) {
switch ($protection) {
case 'up_name':
return !user_access('change own username');
case 'up_mail':
return !user_access('change own e-mail');
case 'up_pass':
return !user_access('change own password');
case 'up_openid':
return !user_access('change own openid');
// Always let user access their own edit page.
case 'up_edit':
return FALSE;
}
}
// If this user hasn't been added to the result array yet, then pull their information.
if (!isset($protections[$uid])) {
$result = db_query("SELECT * FROM {userprotect} WHERE uid = %d AND up_type = 'user'", $uid);
if ($user_array = db_fetch_array($result)) {
$protections[$uid] = $user_array;
}
}
// If per-user protections exist for this user, stop here and return the value of the protection.
if (isset($protections[$uid][$protection])) {
return $protections[$uid][$protection];
}
// Grab the role protections if they haven't already been initialized.
if (!isset($role_protections)) {
$role_protections = variable_get('userprotect_role_protections', array());
}
if (!empty($role_protections)) {
// For each role, check to see if it's enabled for that protection.
// Return TRUE as soon as we find a protected role.
foreach ($roles as $rid => $role) {
if ($role_protections[$rid][$protection]) {
return TRUE;
}
}
}
// No protection enabled.
return FALSE;
}