You are here

function profile2_role_access in Profile 2 7

Same name and namespace in other branches
  1. 7.2 profile2.module \profile2_role_access()

Determines if profile user has current profile available by role.

Parameters

$profile: Profile to check.

Return value

boolean TRUE if profile is available to the profile user.

2 calls to profile2_role_access()
profile2_access in ./profile2.module
Determines whether the given user has access to a profile.
profile2_field_access in ./profile2.module
Implements hook_field_access().

File

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

Code

function profile2_role_access($profile) {
  if (isset($profile->type)) {
    $profile_type = profile2_type_load($profile->type);
    if (!empty($profile_type) && !empty($profile_type->data['roles']) && isset($profile->uid)) {
      $profile_user = user_load($profile->uid);
      $profile_roles = array_keys($profile_type->data['roles']);
      $user_roles = array_keys($profile_user->roles);
      $matches = array_intersect($profile_roles, $user_roles);
      if (empty($matches)) {
        return FALSE;
      }
    }
  }
  return TRUE;
}