You are here

function userprotect_check_bypass in User protect 7

Same name and namespace in other branches
  1. 5 userprotect.module \userprotect_check_bypass()
  2. 6 userprotect.module \userprotect_check_bypass()

Checks to see if the current user can bypass a protection.

Parameters

string $protection: The protection to check for bypass.

object $account: (optional) The user to perform the bypass check on Defaults to the current user.

Return value

bool TRUE if the user can bypass. FALSE otherwise.

6 calls to userprotect_check_bypass()
UserProtectBypassWebTest::doCheckBypass in tests/UserProtectBypassWebTest.test
Tests if bypassing a certain protection is respected.
userprotect_form_alter in ./userprotect.module
Implements hook_form_alter().
userprotect_form_user_profile_form_alter in ./userprotect.module
Implements hook_form_user_profile_form_alter().
userprotect_user_admin_account_validate in ./userprotect.module
Custom validation function for protecting users from the user administration operations.
userprotect_user_cancel_access in ./userprotect.module
Access callback for user cancel pages.

... See full list

1 string reference to 'userprotect_check_bypass'
UserProtectBypassWebTest::doCheckBypass in tests/UserProtectBypassWebTest.test
Tests if bypassing a certain protection is respected.

File

./userprotect.module, line 823
Main module file for the userprotect module.

Code

function userprotect_check_bypass($protection, $account = NULL) {
  $bypass =& drupal_static(__FUNCTION__, array());
  $bypass_defaults =& drupal_static(__FUNCTION__ . '_defaults', NULL);
  if (empty($account)) {
    global $user;
    $account = $user;
  }

  // If not a user admin, no checks necessary.
  if (!user_access('administer users', $account)) {
    return FALSE;
  }

  // Set the static array for the current admin.
  if (!isset($bypass[$account->uid])) {
    $result = db_query("SELECT * FROM {userprotect} WHERE uid = :uid AND up_type = :up_type", array(
      ':uid' => $account->uid,
      ':up_type' => 'admin',
    ));
    if ($admin_array = $result
      ->fetchAssoc()) {
      $bypass[$account->uid] = $admin_array;
    }
  }

  // If a per administrator bypass setting exists, return it.
  if (isset($bypass[$account->uid][$protection])) {
    return $bypass[$account->uid][$protection];
  }
  else {
    if (!isset($bypass_defaults)) {
      $bypass_defaults = variable_get('userprotect_administrator_bypass_defaults', userprotect_administrator_bypass_defaults());
    }
    return isset($bypass_defaults[$protection]) ? $bypass_defaults[$protection] : FALSE;
  }
}