vBulletin Mods

The Official vBulletin Modifications Site
https://www.vbulletin.org/forum/showthread.php?t=325399

[RESOLVED] Conditions being ignored when viewed by guest
by Makaze
17 Jul 2017 17:07

I am editing a template with the following conditional structure:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The template works correctly when viewed by a member who is logged in. However, when a guest views it, this condition gets ignored in both places:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The shown class is added no matter what condition I add around it. I have even tried changing the condition to true === false. That condition is ignored when viewed by a guest. I tested that changes were working by adding {vb:raw} for the variables in the template. The values display correctly immediately after saving. The issue is isolated to the vbulletin condition statement.

Once again, it works properly when logged in, but not when viewing as a guest.

How can I resolve this?

MarkFL 17 Jul 2017 17:36

Try changing it to:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Dave 17 Jul 2017 17:51

The condition $post['userid'] == $bbuserinfo['userid'] checks if the userid of the post is the same as the userid of the current logged in user. Guests have a userid of 0 which is why it never (should) evaluates to true.

Have you tried changing == to ===? That will also match the data type.

Makaze 17 Jul 2017 18:39

Quote:

Originally Posted by Dave (Post 2588563)
The condition $post['userid'] == $bbuserinfo['userid'] checks if the userid of the post is the same as the userid of the current logged in user. Guests have a userid of 0 which is why it never (should) evaluates to true.

Have you tried changing == to ===? That will also match the data type.

Yes. I tested it with true === false as well. The condition was ignored regardless of contents.

--------------- Added 17 Jul 2017 at 18:43 ---------------

Quote:

Originally Posted by MarkFL (Post 2588562)
Try changing it to:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

This had no effect.

Once again, the code works when logged in. It fails when logged out.

Dave 17 Jul 2017 20:38

So if I understand you correctly, your condition always evaluates to true when a guest is viewing it? Thus the class "shown" is always added?

Is the $post variable available in the template? Also, try putting the following in your template before the div that contains the if condition so you can see what it outputs:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Makaze 17 Jul 2017 20:56

No, you are not understanding.

It behaves as if the condition tag does not exist, even if the condition in the quotes is "true === false", instead of my condition I would like to use.

I can access the variables and output them to the screen using {vb:raw post.userid} and {vb:raw bbuserinfo.userid}. They output correctly, including for guests. The variables exist in the template.

Furthermore, the code:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Should never evaluate to true. Yet it does, in this template, while being viewed by a guest.

In other words, it is behaving as if the conditional tag is not there, and just shows the contents.

It has nothing to do with the actual statements in the conditions.

--------------- Added 17 Jul 2017 at 22:57 ---------------

It appeared to be the location of the statement. It works if it is at a tier 2 nesting or global if.

I believe there is a bug related to nesting and guest viewing.

Makaze 23 Jul 2017 17:03

RESOLVED!

The issue was a piece of JavaScript that was adding the shown class after the page had loaded. The reason it did so even if the user was logged out, was because the condition was to find the Add Thanks button, and if it isn't there, add the shown class. The button isn't there for guests, so it added shown to everything.

I apologize for wasting everyone's time.


All times are GMT. The time now is 03:33.

Powered by vBulletin® Version 3.8.14
Copyright © 2021, MH Sub I, LLC dba vBulletin. All Rights Reserved. vBulletin® is a registered trademark of MH Sub I, LLC
Copyright ©2001 - , vbulletin.org. All rights reserved.