You are here

function hook_profile2_access in Profile 2 7

Same name and namespace in other branches
  1. 7.2 profile2.api.php \hook_profile2_access()

Control access to profiles.

Modules may implement this hook if they want to have a say in whether or not a given user has access to perform a given operation on a profile.

Parameters

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

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

$account: (optional) The user to check for. If no account is passed, access is determined for the global user.

Return value

boolean Return TRUE to grant access, FALSE to explicitly deny access. Return NULL or nothing to not affect the operation. Access is granted as soon as a module grants access and no one denies access. Thus if no module explicitly grants access, access will be denied.

See also

profile2_access()

2 functions implement hook_profile2_access()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

profile2_og_access_profile2_access in contrib/profile2_og_access.module
Implements hook_profile2_access().
profile2_profile2_access in ./profile2.module
Implements hook_profile2_access().
1 invocation of hook_profile2_access()
profile2_access in ./profile2.module
Determines whether the given user has access to a profile.

File

./profile2.api.php, line 297
This file contains no working PHP code; it exists to provide additional documentation for doxygen as well as to document hooks in the standard Drupal manner.

Code

function hook_profile2_access($op, $profile = NULL, $account = NULL) {
  if (isset($profile)) {

    // Explicitly deny access for a 'secret' profile type.
    if ($profile->type == 'secret' && !user_access('custom permission')) {
      return FALSE;
    }

    // For profiles other than the default profile grant access.
    if ($profile->type != 'main' && user_access('custom permission')) {
      return TRUE;
    }

    // In other cases do not alter access.
  }
}