This section contains detailed articles elaborating on some of the common issues phpBB users encounter while using the product. Articles submitted by members of the community are checked for accuracy by the relevant phpBB Team. If you do not find the answer to your question here, we recommend looking through the Support Section as well as using the Site Wide Search.

[Howto] Making an on/off switch in acp

Description: I have the X mod/feature, but occasionally I want to hide it from plain view. How can I do this?

In Categories:

Link to this article: Select All
[url=https://www.phpbb.com/support/docs/en/3.0/kb/article/howto-making-an-on+off-switch-in-acp/]Knowledge Base - [Howto] Making an on/off switch in acp[/url]

A lot of people find it useful to enable/disable the appearance of certain parts of their forum and they prefer to have a switch in the ACP to easily turn them on/off. The following article explains a way to do this. In this particular case a member was asking about a way to enable/disable a chat, but you can use it for many different things after - of course - you modify it according to your needs.

OK, so here we go:

  1. Database
    The first thing that you need to do is to create a new field in your database. This field will be either 0 (disabled) or 1 (enabled):

    Code: Select all

    INSERT INTO phpbb_config (config_name, config_value) VALUES ('enable_chat', '0');

    Note that now the field is created in your config table in the database, but you can always create it in a different one, according to your needs (eg when a mod has created its own table but it does not provide a way to be or not to be displayed)
  2. Creating the "switch"
    The second thing we need is to create the "switch". This can be done in includes/functions.php. Find in that file:

    Code: Select all

       // The following assigns all _common_ variables that may be used at any point in a template.

    After, add

    Code: Select all

    'S_ENABLE_CHAT'      => ($config['enable_chat']) ? true : false ,
  3. ACP placement of the switch
    Now that the switch is created, we also need to place it in the ACP, in oder to use it whenever we need it, right? If no ACP control exists for the mod you can always place the code in includes/acp/acp_board.php.
    So, in that file find:

    Code: Select all

          switch ($mode)
          {
             case 'settings':
                $display_vars = array(
                   'title'   => 'ACP_BOARD_SETTINGS',
                   'vars'   => array(

    Notice 2 things :
    a. case 'settings':
    b. 'title' => 'ACP_BOARD_SETTINGS',
    This actually tells you what the specific section is for. In this case it is the "Board Settings" section in ACP. If you need the switch to be somewhere else, just browse through "case 'blahblah':" in that file to find where to put your code.

    E.g.: You want the switch to be in "Board features" section? The correct place should be

    Code: Select all

             case 'features':
                $display_vars = array(
                   'title'   => 'ACP_BOARD_FEATURES',


    I hope you got the point. Back to the edits, now...

    In includes/acp/acp_board.php find:

    Code: Select all

                      'allow_birthdays'      => array('lang' => 'ALLOW_BIRTHDAYS',      'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => true),

    Add, after:

    Code: Select all

    'enable_chat'         => array('lang' => 'ENABLE_CHAT',         'validate' => 'bool',   'type' => 'radio:yes_no', 'explain' => false),

    Notice the 'explain' => false part:
    If we have this to "true" then at the next step we will have to create an additional language entry that will be the explanation of the switch. You don't need to do anything additional in includes/acp/acp_board.php - it is added automatically.
  4. Creating the language entries
    So, now we have created the switch and we have placed it in our ACP. We'll also need to create a language entry for this. In language/en/acp/board.php find:

    Code: Select all

       'BOARD_PM_EXPLAIN'         => 'Enable or disable private messaging for all users.',

    Add, after

    Code: Select all

    'ENABLE_CHAT'               => 'Enable chat',

    If in the previous step we had "'explain' => true" we will need an additional entry:

    Code: Select all

    'ENABLE_CHAT_EXPLAIN'               => 'Select "Yes" to show our chat and "No" to hide it',


    Notice again that this language file has the entries categorized according to where the specific language applies. in this case, we added the language entry in

    Code: Select all

    // Board Features
    $lang = array_merge($lang, array(

    section, since this is the same section we added the switch a while ago. This is not mandatory, but it will keep your files organized ;)
  5. Using the switch in templates
    Now, the only thing left is to use the switch we have just created in our template file. Most mods have their own html files and are included in the existend ones using the following method:

    Code: Select all

    <!-- INCLUDE this_mod_template.html -->

    In our case, if we suppose that chat has been included using the following:

    Code: Select all

    <!-- INCLUDE chat_body.html -->

    we can do the following:
    Open styles/yourstyle/template/chat_body.html and add a new line before the very first line of that file:

    Code: Select all

    <!-- IF S_ENABLE_CHAT -->

    After the last line of that file add

    Code: Select all

    <!-- ENDIF -->

We are done! Now you will be able to show/hide this mod without needing to editing your files every time: You simply set Yes/No in the ACP
I hope you'lll find this Howto useful... :D