You are here

function og_is_group_member in Organic groups 6

Same name and namespace in other branches
  1. 5.8 og.module \og_is_group_member()
  2. 5 og.module \og_is_group_member()
  3. 5.3 og.module \og_is_group_member()
  4. 6.2 og.module \og_is_group_member()

Check a user's membership in a group.

Parameters

gid: An integer or a node object representing the group node.

$include_admins: Whether or not site admins are considered members.

$uid: Pass a user id, or pass NULL in order to check current user.

10 calls to og_is_group_member()
og_approve in ./og.module
og_block_details in ./og.module
og_home_empty in ./og.module
og_menu_access_invite in ./og.module
og_menu_access_picture in modules/og_views/og_views.module

... See full list

1 string reference to 'og_is_group_member'
og_menu in ./og.module

File

./og.module, line 261

Code

function og_is_group_member($gid, $include_admins = TRUE, $uid = NULL) {
  if ($uid) {
    $user = user_load(array(
      'uid' => $uid,
    ));
  }
  else {
    global $user;

    // Adventurous modules can cause us to arrive here before og_init() has fired.
    // See http://drupal.org/node/285696
    if (!isset($user->og_groups)) {
      $user = user_load(array(
        'uid' => $user->uid,
      ));
    }
  }

  // Allow caller to pass in a full $node. Used by menu items.
  if (is_object($gid)) {
    $gid = $gid->nid;
  }
  $groups = array_keys($user->og_groups);
  if ($include_admins) {
    return user_access('administer nodes', $user) || in_array($gid, $groups) ? TRUE : FALSE;
  }
  else {
    return in_array($gid, $groups);
  }
}