diff --git a/og_field_access/og_field_access.module b/og_field_access/og_field_access.module index 000ace9..55217d6 100644 --- a/og_field_access/og_field_access.module +++ b/og_field_access/og_field_access.module @@ -25,11 +25,17 @@ function og_field_access_field_access($op, $field, $entity_type, $entity, $accou if ($entity_type == 'user' && !$id) { return; } + + // if the user does not belong to any groups then og_get_entity_groups will return empty, so return early. + if (!$entity_groups = og_get_entity_groups()) { + return; + } + if (!$id && $op == 'edit' && (og_is_group($entity_type, $entity) || og_is_group_content_type($entity_type, $bundle))) { // This is create form of a non-saved entity, so we check // permissions to access the field, for all the groups the user is a // member. - foreach (og_get_entity_groups() as $group_type => $gids) { + foreach ($entity_groups as $group_type => $gids) { foreach ($gids as $gid) { if (og_user_access($group_type, $gid, $perm)) { return TRUE;