You are here

function variable_access in Variable 7

Same name and namespace in other branches
  1. 6 variable.module \variable_access()
  2. 7.2 variable.module \variable_access()

Check access to variable

All variables are restricted for editing so unless we've got some explicit access variables cannot be edited as default.

Parameters

$variable: Variable name or info array

Related topics

1 call to variable_access()
variable_form_element in ./variable.form.inc
Build form element for a variable
1 string reference to 'variable_access'
variable_admin_menu in variable_admin/variable_admin.module
Implements hook_menu().

File

./variable.module, line 33
Variable API module

Code

function variable_access($variable, $account = NULL) {
  $account = $account ? $account : $GLOBALS['user'];
  if (user_access('administer site configuration', $account)) {
    return TRUE;
  }
  elseif ($variable = _variable_variable($variable)) {
    $group = isset($variable['group']) ? variable_get_group($variable['group']) : array();
    if (!isset($group['access']) && !isset($variable['access'])) {
      return FALSE;
    }
    elseif (isset($group['access']) && !user_access($group['access'], $account)) {
      return FALSE;
    }
    elseif (isset($variable['access']) && !user_access($variable['access'], $account)) {
      return FALSE;
    }
    else {
      return TRUE;
    }
  }
  else {

    // We don't have information for such variable
    return FALSE;
  }
}