MyBB Community Forums

Full Version: Change which usergroups are allowed to view forum when closed
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Title says it all, how do I change which usergroups are allowed to view the forum while it is closed?
By default, when your board is offline, only usergroups that have access to Administration Panel can see your forum.
To allow other usergroups, you need a plugin (as .m. suggested above) or edit core "global.php" file (line 623 in MyBB 1.6.11):

Search:
// If the board is closed, the user is not an administrator and they're not trying to login, show the board closed message
if($mybb->settings['boardclosed'] == 1 && $mybb->usergroup['cancp'] != 1 && !in_array($current_page, $closed_bypass) && (!is_array($closed_bypass[$current_page]) || !in_array($mybb->input['action'], $closed_bypass[$current_page])))

and replace with:
// If the board is closed, forums can be viewed only by the following usergroups (guid):
$allow_usergroups = "4,3,6"; // 4 = administrators, 3 = super-moderators, 4 = moderators
$allow_usergroup = explode(",", $allow_usergroups);
// If the board is closed, the user is not an administrator and they're not trying to login, show the board closed message
if($mybb->settings['boardclosed'] == 1 && !in_array($mybb->user['usergroup'], $allow_usergroup) && !in_array($current_page, $closed_bypass) && (!is_array($closed_bypass[$current_page]) || !in_array($mybb->input['action'], $closed_bypass[$current_page])))

where $allow_usergroups = "4,3,6"; is the variable where you can insert usergroups that you want to be allowed, separated by a comma.

It is advisable to always allow access to administrators. In this case, is better to replace with this code:
// If the board is closed, forums can be viewed only by the following usergroups (guid):
$allow_usergroups = "4,3,6"; // 4 = administrators, 3 = super-moderators, 4 = moderators
$allow_usergroup = explode(",", $allow_usergroups);
// If the board is closed, the user is not an administrator and they're not trying to login, show the board closed message
if($mybb->settings['boardclosed'] == 1 && $mybb->usergroup['cancp'] != 1 && !in_array($mybb->user['usergroup'], $allow_usergroup) && !in_array($current_page, $closed_bypass) && (!is_array($closed_bypass[$current_page]) || !in_array($mybb->input['action'], $closed_bypass[$current_page])))


That's all.
I always avoid plugins where possible, which is basically all the time, thanks for your help.
^ just two cents related to system core files modification

one should take utmost care while modifying core files
backup of original file should be kept (without any edits)
keep track of modifications (may be in a snippets file)

actually we suggest to use patches plugin for modifying the system core files
(2013-11-29, 04:55 PM).m. Wrote: [ -> ]actually we suggest to use patches plugin for modifying the system core files

Very good suggestion!