Create a new group

//***********************************
//***********************************
//********** ADD NEW GROUP **********
//***********************************
//***********************************
function add_new_group ($AdminUserId, $GroupName, $GroupDescription)
{

  //----- CREATE NEW GROUP -----
  $args = array();
  $args['creator_id'] = $AdminUserId;
  $args['name'] = $GroupName;
  $args['description'] = $GroupDescription;
  $args['status'] = 'hidden';

  $group_id = groups_create_group($args);
  if (is_wp_error($group_id))
  {
    //GROUP COULD NOT BE CREATED 
    return(False);
  }
  
  //----- GROUP WAS CREATED -----
  
  //Set group invites allowed by group admin only
  $enable_forum = False;
  $status = 'hidden';
  $invite_status = 'admins';
  $parent_id = False;
  groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_status, $parent_id);
  
  
  return($group_id);
}

Add member to a group

  groups_join_group($GroupId, $UserId);

Remove member from a group

  groups_leave_group($GroupId, $UserId);
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

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