You are here

function subuser_access_create_callback in Subuser 8

Same name and namespace in other branches
  1. 7.2 subuser.module \subuser_access_create_callback()

Determine whether the user has a given privilege.

If not subuser_access_create() is checked to determin if the permission should be grantted for the current request. The 'access callback' for admin/people/create is changed to this function which should be given the string 'administer users'.

Parameters

$string: The permission, such as "administer nodes", being checked for.

$account: (optional) The account to check, if not given use currently logged in user.

Return value

Boolean TRUE if the current user has the requested permission.

File

./subuser.module, line 165
Provides primary Drupal hook implementations.

Code

function subuser_access_create_callback($string, $account = NULL) {
  global $user;
  if (!isset($account)) {
    $account = $user;
  }
  $user_loaded = user_load($account->uid);
  $total_subusers = count(subuser_load_all($account));
  $subuser_limit = field_get_items('user', $user_loaded, 'field_subuser_limit');
  $max_subusers = '';
  if (isset($subuser_limit[0]['value'])) {
    $max_subusers = $subuser_limit[0]['value'];
  }
  drupal_alter('subuser_limit', $max_subusers, $user);
  if (subuser_access_create($account) && ($max_subusers >= $total_subusers || $max_subusers == '')) {
    $static =& drupal_static('user_access');
    $static[$account->uid][$string] = TRUE;
  }
  return user_access($string, $account);
}