You are here

function profile2_access in Profile 2 7.2

Same name and namespace in other branches
  1. 7 profile2.module \profile2_access()

Determines whether the given user has access to a profile.

Parameters

$op: The operation being performed. One of 'view', 'update', 'create', 'delete' or just 'edit' (being the same as 'create' or 'update').

$profile: (optional) A profile to check access for. If nothing is given, access for all profiles is determined.

$account: The user to check for. Leave it to NULL to check for the global user.

Return value

boolean Whether access is allowed or not.

See also

hook_profile2_access()

profile2_profile2_access()

8 calls to profile2_access()
Profile2CRUDTestCase::testAccess in ./profile2.test
Tests optional access parameters.
profile2_category_access in ./profile2.module
Menu item access callback - check if a user has access to a profile category.
profile2_delete_access in ./profile2.module
Determines whether the given user has access to delete a profile.
profile2_page_access in contrib/profile2_page.module
Check access by profile type for the current user.
profile2_page_menu_local_tasks_alter in contrib/profile2_page.module
Implements hook_menu_local_tasks_alter().

... See full list

3 string references to 'profile2_access'
profile2_entity_info in ./profile2.module
Implements hook_entity_info().
profile2_menu in ./profile2.module
Implements hook_menu().
profile2_page_menu in contrib/profile2_page.module
Implements hook_menu().

File

./profile2.module, line 1036
Support for configurable user profiles.

Code

function profile2_access($op, $profile = NULL, $account = NULL) {

  // Check if profile user has current profile available by role.
  if (isset($profile) && !profile2_role_access($profile)) {
    return FALSE;
  }

  // With access to all profiles there is no need to check further.
  if (user_access('administer profiles', $account)) {
    return TRUE;
  }
  if ($op == 'create' || $op == 'update') {
    $op = 'edit';
  }

  // Allow modules to grant / deny access.
  $access = module_invoke_all('profile2_access', $op, $profile, $account);

  // Only grant access if at least one module granted access and no one denied
  // access.
  if (in_array(FALSE, $access, TRUE)) {
    return FALSE;
  }
  elseif (in_array(TRUE, $access, TRUE)) {
    return TRUE;
  }
  return FALSE;
}