MyBB Community Forums

Full Version: PHP in Template, checking if user is in usergroup per id doesn't work.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello there so I'm having some trouble. Now if I want to use PHP inside template I know I need to use the plugin correspondingly, and I am doing that. For now I'm just using conditionals, which I know is working.

<if !in_array($post['usergroup'], array(8, 9, 10, 11, 12)) then>

<else />
<br />

<if in_array($post['usergroup'], array(8)) then>
  <span class="grouptag grouptag_2" style="background-color:#029ddf;border:0px;">&nbsp; WaterSpoof</span>
</if>

<if in_array($post['usergroup'], array(9)) then>
  <span class="grouptag grouptag_2" style="background-color:#029ddf;border:0px;">&nbsp; WaterSpoof</span>
</if>

<if in_array($post['usergroup'], array(10)) then>
  <span class="grouptag grouptag_2" style="background-color:#029ddf;border:0px;">&nbsp; WaterSpoof</span>
</if>

<if in_array($post['usergroup'], array(11)) then>
  <span class="grouptag grouptag_2" style="background-color:#029ddf;border:0px;">&nbsp; WaterSpoof</span>
</if>

<if in_array($post['usergroup'], array(12)) then>
  <span class="grouptag grouptag_2" style="background-color:#029ddf;border:0px;">&nbsp; WaterSpoof</span> 
</if>

<br />
</if>
The above is what I'm trying to do. And if I use this
<if !in_array($post['usergroup', array(8)) then>
do something
</if>
it will amazingly work, because it won't be able to find the post usergroup. Now I know that already, but I've tried almost everything to grab the correct GID, and amazingly not working. I don't want the user's current selected primary group, I want to check if the user is part of a group. And if it is I want to echo, or rather show a grouptag.
This is all inside the POSTBIT template, between 
<div class="author_information">
			<strong><span class="largetext">{$post['profilelink']}</span></strong> {$post['onlinestatus']}<br />
			<span class="smalltext">
				<span class="grouptag grouptag_{$usergroup['gid']}">&nbsp; {$post['usertitle']}</span><br />

AND
<span style="text-align: center;" class="userstar star_{$post['stars']}" title="{$post['usertitle']}"></span><br />
				{$post['groupimage']}
			</span>
	</div>

I have also tried using globals etc.
Please, any input would be lovely, I am appreciating your time and help so much Smile
I'm too much of a noob with MyBB :3
In which template are you trying to accomplish this? If it is inside some postbit template then $post['usergroup'] and $post['additionalgroups'] are the two variables you need.
<if $post['usergroup'] == 1 || my_strpos(','.$post['additionalgroups'].',', ',1,') then>
foo
</if>

You could also add is_member() to the white list file of functions allowed. Or perhaps it is already there, I don't know.
(2019-01-09, 07:58 AM)Omar G. Wrote: [ -> ]In which template are you trying to accomplish this? If it is inside some postbit template then $post['usergroup'] and $post['additionalgroups'] are the two variables you need.
<if $post['usergroup'] == 1 || my_strpos(','.$post['additionalgroups'].',', ',1,') then>
foo
</if>

You could also add is_member() to the white list file of functions allowed. Or perhaps it is already there, I don't know.

Hey Omar, thanks for your help, I can't really figure out how I get this to work, because it does not for me. Yes I am using it in the temlpate for postbit (postbit).

This is the code I am trying right now, and also shows what I'm trying to do.

<if $post['usergroup'] != 8 || $post['usergroup'] != 9 || $post['usergroup'] != 10 || $post['usergroup'] != 11 || $post['usergroup'] != 12 || my_strpos(','.$post['additionalgroups'].',', ',8,') || my_strpos(','.$post['additionalgroups'].',', ',9,') || my_strpos(','.$post['additionalgroups'].',', ',10,') || my_strpos(','.$post['additionalgroups'].',', ',11,') || my_strpos(','.$post['additionalgroups'].',', ',12,') then>
// User not in either group, double checked.
<else />

// Output Correct Data
<if $post['usergroup'] == 8 || my_strpos(','.$post['additionalgroups'].',', ',8,') then>
  <span style="text-align: center;margin-top:3px;" class="grouptag grouptag_2" style="background-color:#029ddf;border:0px;">&nbsp; WaterSpoof</span> <br />
</if>

<if $post['usergroup'] == 9 || my_strpos(','.$post['additionalgroups'].',', ',9,') then>
  <span style="text-align: center;margin-top:3px;" class="grouptag grouptag_2" style="background-color:#029ddf;border:0px;">&nbsp; Global</span> <br />
</if>

<if $post['usergroup'] == 10 || my_strpos(','.$post['additionalgroups'].',', ',10,') then>
  <span style="text-align: center;margin-top:3px;" class="grouptag grouptag_2" style="background-color:#029ddf;border:0px;">&nbsp; AFort</span> <br />
</if>

<if $post['usergroup'] == 11 || my_strpos(','.$post['additionalgroups'].',', ',11,') then>
  <span style="text-align: center;margin-top:3px;" class="grouptag grouptag_2" style="background-color:#029ddf;border:0px;">&nbsp; Vengeance</span> <br />
</if>

<if $post['usergroup'] == 12 || my_strpos(','.$post['additionalgroups'].',', ',12,') then>
  <span style="text-align: center;margin-top:3px;" class="grouptag grouptag_2" style="background-color:#029ddf;border:0px;">&nbsp; Cyber</span> <br />
</if>

</if>
Try simple things first then.
<if true then>
uid: {$post['usergroup']}
</if>

What happens?