Skip Navigation

[Resolved] unexpected output when using a wpvcondition inside a toolset access rule

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to check user role and display conditional content based on that

Solution:
You can use [wpv-conditional] shortcode to check with multiple role and display conditional content based on that.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/unexpected-output-when-using-a-wpvcondition-inside-a-toolset-access-rule/#post-857429

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by Jim 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#855967

Jim

I am using a wpv condition inside a toolset access rule and the output is messed up.
The code is inside a visual editor cel in a toolset layout.

This is the code:

[toolset_access role="Administrator" operator="allow"]
	[wpv-conditional if="( $(wpcf-pdf-reader-ads) ne '' )"]
		<a href="#"><div class="imgtexttest">Klik hier voor de interactieve PDF</div></a>
	[/wpv-conditional]
[/toolset_access]

and this is the output (for an administrator):

<p>		<a href="#"></a></p><a href="#">
<div class="imgtexttest">Klik hier voor de interactieve PDF</div>
</a><p><a href="#"></a></p>

And the "automatically instert paragraphs" for this field is turned off!

Any idea?

#856116

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I do not know why you use [toolset_access] shortcode as you can achieve this with single [wpv-conditional] shortcode and check both condition using "And"

For example:

[wpv-conditional if="( '[wpv-current-user info='role']' eq 'administrator' ) AND ( $(wpcf-pdf-reader-ads) ne '' )"]
 <a href="#"><div class="imgtexttest">Klik hier voor de interactieve PDF</div></a>
 [/wpv-conditional]

More info:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#856148

Jim

Wow, didn't know that you could select user roles with this...
But why not use toolset access for this? Is that a bad idea, and why? When to use toolset access?

In the meanwhile I will try to set it up like your example, but first I need your help setting this up with multiple user roles...
With toolset I used this rule:

[toolset_access role="Administrator,Klasse 1,Klasse 2,Klasse 4" operator="allow"]

How can I translate that into the new conditional output code?

#856702

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

But why not use toolset access for this? Is that a bad idea, and why? When to use toolset access?
==> Well - its bad idea as you already have conditional shortcode available that serve same purpose. you should use access shortcode when you have no conditional statement inside.

Please try to use following condition:

[wpv-conditional if="( '[wpv-current-user info='role']' eq 'administrator' ) OR ( '[wpv-current-user info='role']' eq 'klasse-1' ) OR ( '[wpv-current-user info='role']' eq 'klasse-2' )  OR ( '[wpv-current-user info='role']' eq 'klasse-4' ) AND ( $(wpcf-pdf-reader-ads) ne '' )"]
 <a href="#"><div class="imgtexttest">Klik hier voor de interactieve PDF</div></a>
 [/wpv-conditional]
#857356

Jim

Wow minesh, great thanks, I think that might work.
I do have one more little problem and that has to do with the next condition:

	[wpv-conditional if="( '[wpv-current-user info='role']' eq 'administrator' ) OR ( '[wpv-current-user info='role']' eq 'klasse-1' ) OR ( '[wpv-current-user info='role']' eq 'klasse-2' )  OR ( '[wpv-current-user info='role']' eq 'klasse-4' ) AND ( $(wpcf-pdf-reader-ads) eq '' )" debug="true"]
		[types field='cover-image_je' class="covimage ia124" style="width:100%" alt='cover afbeelding' size='medium_large' align='none' resize='proportional'][/types]
	[/wpv-conditional]

the "AND" part of this condition should check if the field is empty. In this case it is not but it still displays...

The debug info is this:

####################
wpv-conditional attributes
####################
Array
(
[if] => ( 'administrator' = 'administrator' ) OR ( 'administrator' = 'klasse-1' ) OR ( 'administrator' = 'klasse-2' ) OR ( 'administrator' = 'klasse-4' ) AND ( $(wpcf-pdf-reader-ads) = '' )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( 'administrator' = 'administrator' ) OR ( 'administrator' = 'klasse-1' ) OR ( 'administrator' = 'klasse-2' ) OR ( 'administrator' = 'klasse-4' ) AND ( $(wpcf-pdf-reader-ads) = '' )
--------------------
After replacing 1 general variables and comparing strings: ( 'administrator' = 'administrator' ) OR ( 'administrator' = 'klasse-1' ) OR ( 'administrator' = 'klasse-2' ) OR ( 'administrator' = 'klasse-4' ) AND ( $(wpcf-pdf-reader-ads) = '' )
Comparing administrator to administrator
After replacing 2 general variables and comparing strings: ( 'administrator' = 'administrator' ) OR ( 'administrator' = 'klasse-1' ) OR ( 'administrator' = 'klasse-2' ) OR ( 'administrator' = 'klasse-4' ) AND ( $(wpcf-pdf-reader-ads) = '' )
Comparing administrator to klasse-1
After replacing 3 general variables and comparing strings: ( 'administrator' = 'administrator' ) OR ( 'administrator' = 'klasse-1' ) OR ( 'administrator' = 'klasse-2' ) OR ( 'administrator' = 'klasse-4' ) AND ( $(wpcf-pdf-reader-ads) = '' )
Comparing administrator to klasse-2
After replacing 4 general variables and comparing strings: ( 'administrator' = 'administrator' ) OR ( 'administrator' = 'klasse-1' ) OR ( 'administrator' = 'klasse-2' ) OR ( 'administrator' = 'klasse-4' ) AND ( $(wpcf-pdf-reader-ads) = '' )
Comparing administrator to klasse-4
--------------------
Converted expression: ( 'administrator' = 'administrator' ) OR ( 'administrator' = 'klasse-1' ) OR ( 'administrator' = 'klasse-2' ) OR ( 'administrator' = 'klasse-4' ) AND ( '/wp-content/uploads/2018/lookbook2-adv/NTVH2-2018.html' = '' )

As you can see above - > AND ( '/wp-content/uploads/2018/lookbook2-adv/NTVH2-2018.html' = '' )
this should not turn true, but it does.

Any idea why?

#857429

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please try following code: - I grouped the role condition with () brackets.

[wpv-conditional if="( ('[wpv-current-user info='role']' eq 'administrator' ) OR ( '[wpv-current-user info='role']' eq 'klasse-1' ) OR ( '[wpv-current-user info='role']' eq 'klasse-2' )  OR ( '[wpv-current-user info='role']' eq 'klasse-4' ) ) AND ( $(wpcf-pdf-reader-ads) eq '' )" debug="true"]
    [types field='cover-image_je' class="covimage ia124" style="width:100%" alt='cover afbeelding' size='medium_large' align='none' resize='proportional'][/types]
[/wpv-conditional]
#857668

Jim

Great! All working now.
Happy 🙂