Mybb is a great script and it presents you with bunch of settings which you can use to set all kinds of permissions but the problem is when you try to deny access to the forum it will not be shown on the home page.
Your objective is to have the forum visible on index but to make it private in other words only certain user groups will have access to it.
I have create this simple plugin and the thing is it doesn't add setting to admin control panel so you have to edit it manually sorry still learning PHP.
<?php
if(!defined('IN_MYBB'))
{
die();
}
$plugins->add_hook('forumdisplay_start','privateforum');
$plugins->add_hook('showthread_start','privateforum');
$plugins->add_hook("newthread_start", "privateforum");
$plugins->add_hook("newreply_start", "privateforum");
$plugins->add_hook("datahandler_post_validate_post", "privateforum_post");
function privateforum_info()
{
return array
(
'name'=>'Private Forum',
'description'=>'Deny Access to certain user groups',
'website'=>'http:// letsforum.com',
'author'=>'Victor Dub',
'version'=>'1',
'compatibility'=>'14*,16*',
);
}
function privateforum()
{
global $mybb, $thread;
$fid = intval($mybb->input['fid']);
if(!in_array($mybb->user['usergroup'], array('x')) && in_array($fid, array('x')))
{
error_no_permission();
}
$check = $thread['fid'];
if(!in_array($mybb->user['usergroup'], array('x')) && in_array($check, array('x')))
{
error_no_permission();
}
}
function privateforum_post(&$post)
{
global $mybb, $thread;
$checkpost = $thread['fid'];
if(!in_array($mybb->user['usergroup'], array('x')) && in_array($checkpost, array('x')))
{
error_no_permission();
}
}
?>
Create an empty PHP file copy and paste the code above then save the file as: privateforum.php
Upload it to /inc/plugins folder/directory.
Activate it from ACP.
Important!
You have to configure the plugin before using it.
if(!in_array($mybb->user['usergroup'], array('x')) && in_array($forum['fid'], array('x')))
In the line above replace x with usergroup ID and Forum ID
This is an array so if you want to add more ids then use:
array('x','x','x','x')
Tested and works.
Updated code!!!!! Now it will deny access to forum and threads!
New Update!!! I was looking for a way to replace posts and threads number with "Private" using this plugin but it's just not gonna happen so we need to do a bit of core edit here people!
Open functions_forumlist.php which is located in ./inc directory and find:
if($forum['linkto'] != '' || $hideinfo == true || $hidecounters == true)
{
$posts = "-";
$threads = "-";
}
// Otherwise, format thread and post counts
else
{
$posts = my_number_format($forum['posts']);
$threads = my_number_format($forum['threads']);
}
Add this code below:
//Function for privateforum plugin
$privateforum = $forum['fid'];
if(in_array($privateforum, array('x')))
{
$posts = "Private";
$threads = "Private";
}
Don't forget to add FID to the private forum here:
if(in_array($privateforum, array('x')))