You are here

function view_profiles_perms_access in View profiles permissions 7

Same name and namespace in other branches
  1. 6 view_profiles_perms.module \view_profiles_perms_access()

Access callback for user profiles.

1 call to view_profiles_perms_access()
view_profiles_perms_entity_metadata_user_access in ./view_profiles_perms.module
Access callback to override entity_metadata_user_access().
1 string reference to 'view_profiles_perms_access'
view_profiles_perms_menu_alter in ./view_profiles_perms.module
Implements hook_menu_alter().

File

./view_profiles_perms.module, line 51
Restricts viewing user profiles based on user roles

Code

function view_profiles_perms_access($account = NULL) {
  global $user;
  if (!isset($account)) {
    $account = $user;
  }

  // First check user module's access
  $access = user_view_access($account);
  if (!$access) {

    // Check our own permissions.
    foreach ($account->roles as $rid => $role_name) {

      // Annonymous and authenticated user roles get skipped
      if ($rid != DRUPAL_ANONYMOUS_RID && $rid != DRUPAL_AUTHENTICATED_RID) {
        $perm_name = view_profiles_perms_permission_name($role_name);
        if (!empty($perm_name)) {
          $perm_name = key($perm_name);
          $access = user_access($perm_name);
          if ($access === TRUE) {
            break;
          }
        }
      }
    }
  }
  return $access;
}