Back to vBulletin 3 Articles

Create Private Group Forums (automatically)
by xxclixxx 13 Mar 2008

I'm in the process of integrating vBulletin into my existing site. Part of that, is I have Teams that have their own private forums. I found the Add new Users article very helpful, so I figured why not share what I figured out too.

Basically what this does is creates a new usergroup, creates a new child forum, and restricts access to the child forum to registered users, and gives access to the new usergroup.

You will need to edit the parentid in the code to the ID of your forum these will be children of. You don't need to do any special permissions to that main forum either, as the permissions are set to the sub children.

You'll notice three sets of forumpermissions. Only edit the one that's below the comment saying to edit that one, if necessary. The others are purposely set to 0 to give the private forums privacy =P

PHP Code:
$teamarray = array (
 
'title' => "Team Title",
 
'description' => "Team Description",
 
'usertitle' => "Team User Title",
 
'opentag' => '',
 
'closetag' => '',
 
'passwordexpires' => '',
 
'passwordhistory' => '',
 
'ispublicgroup' => '0',
 
'canoverride' => '1',
 
'forumpermissions' => 0,
 
'genericpermissions' => 0,
 
'attachlimit' => '1000000',
 
'pmquota' => '0',
 
'pmpermissions' => 0,
 
'pmsendmax' => '5',
 
'calendarpermissions' => 0,
 
'wolpermissions' => 1,
 
'adminpermissions' => 0,
 
'genericoptions' => 41,
 
'profilepicmaxwidth' => '100',
 
'profilepicmaxheight' => '100',
 
'profilepicmaxsize' => '25000',
 
'avatarmaxwidth' => '50',
 
'avatarmaxheight' => '50',
 
'avatarmaxsize' => '20000',
 
'signaturepermissions' => 0,
 
'sigpicmaxwidth' => '',
 
'sigpicmaxheight' => '',
 
'sigpicmaxsize' => '',
 
'sigmaxrawchars' => '',
 
'sigmaxchars' => '',
 
'sigmaxlines' => '',
 
'sigmaxsizebbcode' => '7',
 
'sigmaximages' => '',
);

$db->query_write(fetch_query_sql($teamarray'usergroup'));
$usergroupid $db->insert_id();

$forumdata =& datamanager_init('Forum'$vbulletinERRTYPE_CP);
$forumdata->set('title''Team Name Private Forum');
$forumdata->set('description''The private forum for Team ');
$forumdata->set('link''');
$forumdata->set('displayorder'1);
$forumdata->set('parentid'18);
$forumdata->set('daysprune', -1);
$forumdata->set('defaultsortfield''lastpost');
$forumdata->set('defaultsortorder''desc');
$forumdata->set('showprivate'0);
$forumdata->set('newpostemail''');
$forumdata->set('newthreademail''');
$forumdata->set_bitfield('options''moderatenewpost'0);
$forumdata->set_bitfield('options''moderatenewthread'0);
$forumdata->set_bitfield('options''moderateattach'0);
$forumdata->set_bitfield('options''styleoverride'0);
$forumdata->set_bitfield('options''canhavepassword'1);
$forumdata->set_bitfield('options''cancontainthreads'1);
$forumdata->set_bitfield('options''active'1);
$forumdata->set_bitfield('options''allowposting'1);
$forumdata->set_bitfield('options''indexposts'1);
$forumdata->set_bitfield('options''allowhtml'0);
$forumdata->set_bitfield('options''allowbbcode'1);
$forumdata->set_bitfield('options''allowimages'1);
$forumdata->set_bitfield('options''allowsmilies'1);
$forumdata->set_bitfield('options''allowicons'1);
$forumdata->set_bitfield('options''allowratings'1);
$forumdata->set_bitfield('options''countposts'1);
$forumdata->set_bitfield('options''showonforumjump'1);
$forumdata->set(styleid, -1);
$forumdata->set(password'');

$forumid $forumdata->save();

// Edit the below forumpermissions
$querydata = array(
    
'usergroupid' => $usergroupid,
    
'forumpermissions' => 1048575,
    
'forumid' => $forumid
);
        
$query fetch_query_sql($querydata'forumpermission');
$db->query_write($query);

$querydata = array(
    
'usergroupid' => 2,
    
'forumpermissions' => 0,
    
'forumid' => $forumid
);
        
$query fetch_query_sql($querydata'forumpermission');
$db->query_write($query);        
        
build_forum_permissions(); 
There you go, it should be enough to get you started quicker than it took me. Oh and before you ask, the only included files I am using are these, however I'm also doing other functions as well so I don't really know which ones are required but you can just remove each file one by one until it flips out and wants the file back =P

PHP Code:
define('THIS_SCRIPT'__FILE__);
define('FORUMPATH''/home/startx/public_html/forums');
$cwd getcwd();
chdir(FORUMPATH);
require_once(
'./includes/init.php'); // includes class_core.php
require_once('./includes/class_dm.php'); // for class_dm_user.php
require_once('./includes/class_dm_user.php'); // for user functions
require_once('./includes/functions.php'); // vbsetcookie etc.
require_once('./includes/functions_login.php'); // process login/logout 

vblts.ru supports vBulletin®, 2022-2024