Action: Hidden Content

Compatible with: R6.1
Current version: 1.4
Credits: Tann San

Repo: action/hiddencontent.php

{{hiddencontent username="User1,User2,User3" usergroup="Admins" text="Hidden text" alt="Shown to users who dont meet the login requirements"}}



if (!defined('IN_WACKO'))

    Hidden Content Wrapper

    Version 1.4
    David Millington aka Tann San

$info = <<<EOD
    Shows hidden content based on user group or user name.


    [username    = <comma deliminated list of user names>] - optional - username="TannSan,BillyBob"
    [usergroup    = a single user group name] - optional - usergroup="Admins"
    [text        = text to display if user meets login requirements]
    [alt        = alternative text to display to users who do not meet the login requirements] - optional

// set defaults
$alt        ??= '';
$help        ??= 0;
$text        ??= '';
$usergroup    ??= '';
$username    ??= '';

if ($help)
    $tpl->help    = $this->help($info, 'hiddencontent');

if ($usergroup !== '' || $username !== '')
    $show_content = false;

    // Check if user is the named user
    if (in_array($this->get_user_name(), explode(',', $username)))
        $show_content = true;
    else if (is_array($this->db->aliases))
        // Check if current user is in the specified $usergroup
        // don't bother if we already identified the user as having access
        foreach ($this->db->aliases as $group => $members)
            if ($group === $usergroup)
                if (in_array($this->get_user_name(), explode(',', $members)))
                    $show_content = true;

    if ($show_content)
        $tpl->text = $this->format($text);
else if ($alt !== '')
    $tpl->text = $this->format($alt);


[ === main === ]
	[ ' help ' ]
	[ ' text ' ]	

1. Documentation

Hides content on a page based on either the currently logged in users name or their user group. The username attribute lets you use a comma deliminated list of user names or just one on its own. The usergroup attribute lets you specify a single user group. You can use either one or both of the attributes so you could for example allow the entire “Admins” group and five non admin users to view the content or you could just allow a single user. The text attribute lets you use wiki text so you can still apply all the wiki formatting to the hidden content. To split it onto new lines use the wiki newline tag.

Note that this action does not prevent people from simply editing the page and reading the hidden content. It is meant to be used on pages which other logged in users do not have edit access to. Say Bob owns pageA. Alice once logged in can read pageA but not edit it. Bob can write a message on the page that only Alice can read using this action. Other logged in users who do not have edit access to the page cannot see the text. Non logged in users also cannot read the text.

2. Changelog

1.0 - Intitial version
1.1 - Added optional alt attribute which shows content to users who don't meet the login requirements
1.2 - Updated to work with R5.0
1.3 - Updated to work with R5.5 and R.6.0
1.4 - Updated to work with R.6.1 (PHP 8.0, Null coalescing assignment operator)

Referring pages:

  1. Dev/PatchesHacks