Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.

Thread: 

MYBB make forum private with a plugin mod

Ads
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#1
Support Team
What's up ladies here I am again posting trying to help others looking for a way to make a forum private you know when user tries to access it gets a deny message saying that it has no permissions to access it.

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 Code:
<?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.

PHP Code:
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:

PHP Code:
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:
PHP Code:
//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:
PHP Code:
if(in_array($privateforum, array('x'))) 
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#2
Member
Thanks Marcus
do you mean by this way it shows the forum in Index but user can't access it ?
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#3
Support Team
MYBB has a permission setting to deny access to the forum based on the usergroup it's called Can view forum but the problem is it will hide the forum which means forum will not show on home page can only be accessed if you know the URL.

With this plugin you are able to deny access to any usergroup you want, and the best of all, forum will be shown on index.

Ideal if you have a VIP or Premium membership usergroups and you want only them to have access to some forum.
destroyer Offline referral

Posts: 430
Joined: Jul 2013
Reputation: 3

#4
Senior Member
Thanks Marcus I was really looking for a way to create VIP forum for subscribers but juts couldn't find any plugin for that this works great.
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#5
Member
It works ,but it will deny access of all the forum for that usergroup
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#6
Support Team
Lets say I have created 2 VIP/Private forums that have FID20 and FID10 and I want to allow access to it only to user-groups ID 3,4,6,10

The code to use is:

PHP Code:
if(!in_array($mybb->user['usergroup'], array('3','4','6','10')) && in_array($forum['fid'], array('10','20'))) 

Everyone will be denied access except users from groups mentioned above!


There was a bug sorry about that Smile
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#7
Member
Thanks, but it didn't work

I used this code :
PHP Code:
if(!in_array($mybb->user['usergroup'], array('3','1','6','10')) && in_array($forum['fid'], array('1','2'))) 

with this code administrator group will deny access of FID 1 & 2
but when I tested, administrator group was denied access of all the forums
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#8
Support Team
Thanks for your feedback. You were right it was blocking all forums cause I am still really bad at PHP. I have just updated the plugin. Tested it and it works as advertised.
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#9
Member
Thanks marcus
you're really good and better than someone I had seen

I tried but it didn't deny access of any group
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#10
Support Team
This time I am sure it works cause I have tested it! Please use an updated plugin version.

This code means that if a user is in one of those groups error will show!
PHP Code:
if(in_array($mybb->user['usergroup'], array('3','4','6')) 

If you add ! symbol before in_array like so !in_array this means that if users is not in the one of those groups error will show!

Check user-group IDs and forum FIDs.
lion Offline referral

Posts: 122
Joined: May 2014
Reputation: 0

#11
Member
(07-18-2014 06:35 PM)marcus_avrelius Wrote:  This time I am sure it works cause I have tested it! Please use an updated plugin version.

This code means that if a user is in one of those groups error will show!
PHP Code:
if(in_array($mybb->user['usergroup'], array('3','4','6')) 

If you add ! symbol before in_array like so !in_array this means that if users is not in the one of those groups error will show!

Check user-group IDs and forum FIDs.

Yeah Heart
it works

it will deny access of that forum but users can view the post of that forum
that will be good if users deny access of viewing posts too
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#12
Support Team
No need a plugin for this. In admin control panel>> Forums & Posts >> Forum of your choice >> Options >> Permissions. Group >> Set Custom Permissions >> Viewing >> uncheck Can view threads within forum?
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#13
Support Team
Hi I have upgraded the plugin and now it also checks if the user has permission to view the thread in the private forum.
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#14
Support Team
Just released new update! Check user permissions during posting new reply and thread
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#15
Support Team
Just released new update ladies now thread and posts value is replaced with the word "Private"





User(s) browsing this thread: 1 Guest(s)