[For 1.8] Display unique messages for different parts of your forum or usergroups
#1
Hi,

In this tutorial I will be showing you how you can display an unique message, to unique users, sections, threads or usergroups. We will be needing a plugin and some small PHP codes for this, but I will guide you through this. 

Requirements:

Step 1:
Upload Template conditionals and activate it from the plugins tab. 

Step 2:
Determine what you want to show, in this example I will be showing new members an alert to read our help documents. 

Step 3:
Open the template that you want your message in, mine is header templates -> header. I want my message to appear before everything else, so I put it below the container and above {pm_notice} and other stuff. 
Check screenshot: https://i.imgur.com/Axs9azp.png

Step 4:
Use the following code:
<if $mybb->user['usergroup'] == "USERGROUPIDHERE" then>
Your message here
<else>
</if>
This uses the ID of the display usergroup, if you want to show a message to users whom are part of a group but do not have it as display, click here.

Step 5:
Edit the "USERGROUPIDHERE" to your desired usergroup. If you want to use multiple groups, use this code:
<if $mybb->user['usergroup'] == "1" || $mybb->user['usergroup'] == "2" then>
Change the 1 & 2 to whatever usergroup you desire.

Step 6:
Edit the "your message here" to your desired HTML.


Additional information:
You can use this practically for anything you want. I am currently just showing that message to users who have the registered usergroup and a couple warning messages that display when posting a new thread in a certain section. If you want to display a message in a certain section, change the top line with this:
<if $forum['fid'] == "FORUMIDHERE" then>



If you need help or assistance, you can tweet me at @Perileos 
My help/assistance is free as long as you can respect me and my time. 

Kind regards,
A. Longbeach
Reply
#2
Thank you for your contribution.

As a suggestion, consider not using just $mybb->user['usergroup'] for group checking, as users might have additional groups. Consider instead using the is_member() function, which IIRC is enabled in Template Conditionals.

Should be something along the lines of <if is_member(1, 2) then></if>.
Reply
#3
(2020-03-22, 05:02 AM)Omar G. Wrote: Thank you for your contribution.

As a suggestion, consider not using just $mybb->user['usergroup'] for group checking, as users might have additional groups. Consider instead using the is_member() function, which IIRC is enabled in Template Conditionals.

Should be something along the lines of <if is_member(1, 2) then></if>.

Thank you for addition. 
My users will always keep the registered usergroup, however can change their display usergroup. Hence why I have set it up like this.

I will add in the original post that it uses the display usergroup id.
Reply
#4
The display group is a 3th value ($mybb->user['displaygroup']) which users can pick from either their primary group ($mybb->user['usergroup']) or additional (secondary) ($mybb->user['additionalgroups']) groups. MyBB checks both groups for permissions, whereas your code only checks for the primary group.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)