You are here

function og_subscribe in Organic groups 5

Same name and namespace in other branches
  1. 5.8 og.module \og_subscribe()
  2. 5.2 og.module \og_subscribe()
  3. 5.3 og.module \og_subscribe()
  4. 5.7 og.module \og_subscribe()
  5. 6.2 og.pages.inc \og_subscribe()
  6. 6 og.module \og_subscribe()
1 string reference to 'og_subscribe'
og_menu in ./og.module

File

./og.module, line 684

Code

function og_subscribe($gid, $uid = NULL) {
  global $user;
  if (is_null($uid)) {
    if ($user->uid) {
      $account = $user;
    }
    else {
      drupal_set_message(t('In order to join this group, you must login or register a new account. After you have successfully done so, you will need to request membership again.'));
      drupal_goto('user');
    }
  }
  else {
    $account = user_load(array(
      'uid' => $uid,
    ));
  }
  $node = node_load($gid);
  if ($node->og_selective >= OG_INVITE_ONLY || $node->status == 0 || !og_is_group_type($node->type)) {
    drupal_access_denied();
    exit;
  }

  // only admins can add another member
  if ($account->uid != $user->uid && !og_is_node_admin($node)) {
    drupal_access_denied();
    exit;
  }
  else {
    if (isset($account->og_groups[$node->nid])) {
      drupal_set_message(t('@user is already a member the group @group', array(
        '@user' => $account->name,
        '@group' => $node->title,
      )));
      drupal_goto('node/' . $node->nid);
    }
    else {
      return drupal_get_form('og_confirm_subscribe', $gid, $node, $account);
    }
  }
}