Get the current group ID

  //GET THIS GROUPS ID
  $guid = bp_get_current_group_id();
  if (!is_numeric($guid))
    die('Unable to get group ID');

Get groups user is a member of

Note – in our tests using a different users user_id instead of bp_displayed_user_id() returned zero results – appears to be a buddypress bug

  $GroupIds = groups_get_user_groups(bp_loggedin_user_id());
  $GroupIds = $GroupIds['groups'];
  foreach ($GroupIds as $GroupId)
  {
  }

Does group exist?

  if (bp_get_group($GroupId) === False)   //Returns the Group object if found, false otherwise.
  {
    return('Invalid group');
  }

Is user group admin?

  if (groups_is_user_admin(bp_loggedin_user_id(), $GroupId) === False)    //(Returns False or ID of the membership if the user is admin)
  {
    return('Invalid user');
  }

Is user a member of group?

  if (groups_is_user_member( bp_loggedin_user_id(), $GroupId ) === False)    //Returns False or ID
    return("Not authorised");

  if (groups_is_user_member( bp_loggedin_user_id(), $GroupId ) !== False)    //Returns False or ID
    return("User is a member");

Get group name

  $GroupObject = groups_get_group($GroupId);
  $GroupName = $GroupObject->name;

Get group slug

  $GroupObject = groups_get_group($GroupId);
  $GroupSlug = $GroupObject->slug;

Get Group Admins

  $GroupAdmins = groups_get_group_admins($GroupId);
  //print_r($GroupAdmins);
  $GroupAdminsUserIds = array();
  foreach ($GroupAdmins as $NextGroupAdmin)
  {
    $GroupAdminsUserIds[] = $NextGroupAdmin->user_id;
  }
  if (empty($GroupAdminsUserIds))
    return("Could not find group admin");

Get Group Members

  //------ GET GROUP MEMBERS -----
  $GroupMembers = groups_get_group_members(array('group_id' => $GroupId, 'exclude_admins_mods' => false));
  //print_r($GroupMembers);
  $GroupMembersUserIds = array();
  foreach ($GroupMembers['members'] as $GroupMember)
    $GroupMembersUserIds[] = $GroupMember->ID;
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *