Skip Navigation

[Resolved] wpv-conditional used, but failing to work for certain roles..

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

Problem: I would like to use conditional HTML to make sure the current User is also the author of the post.

Solution: Use the correct wpv-user and wpv-current-user shortcodes in your conditional HTML statements.

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/

This support ticket is created 6 years, 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1092038

We have a site using Toolset, Beaver Builder, Paid memberships pro. Its goal is to let people post job offers. There are 2 options for posting, be a yearly member, and then post all you want, or pay $20 for 1 post without being a yearly member.

We've added an edit link at the top of the posts to let people access the Edit version of the Post form. We use some wpv-conditional shortcodes there to make the (EDIT) link appear, IF the user is the author, OR if the user is one of the 2 admins..

We've had a very hard time getting it to work and would love if someone could look over the Access Control permissions and that bit of code to se where we go wrong?

PS: Do you still offer those shared desktop sessions? It might help explain this better. OR I could record a screencast if needed.. It probably wouldn't hurt 🙂

PPS: I've tried doing a Duplicator backup but I think WPEngine must block it, it fails.. I can do UpdraftPlus, or you can take one if you want and know Duplicator better than me ;)..

#1092390

I'll be glad to take a look. I logged in and checked the Listings Layout and found this code I assume you are referring to:

[wpv-conditional if="( '[wpv-post-author]' eq '[wpv-current-user]' )"]
[toolset-edit-post-link layout_slug="edit-listing" class="edit-post-link"](edit)[/toolset-edit-post-link]
[/wpv-conditional]

[wpv-conditional if="( '[wpv-user]' eq 'jobsnvf' )"]
[toolset-edit-post-link layout_slug="edit-listing" class="edit-post-link"](edit)[/toolset-edit-post-link]
[/wpv-conditional]

[wpv-conditional if="( '[wpv-user]' eq 'nomad411' )"]
[toolset-edit-post-link layout_slug="edit-listing" class="edit-post-link"](edit)[/toolset-edit-post-link]
[/wpv-conditional]

Anytime you want to troubleshoot conditional HTML, the first step is to add the debug="true" parameter like this:

[wpv-conditional if="( '[wpv-post-author]' eq '[wpv-current-user]' )" debug="true"]

Please add this parameter to all 3 conditional shortcodes.

Next, I can see the only content inside these conditionals is the toolset-edit-post-link shortcode. Please add some basic text content inside each conditional to help during testing, like this:

[wpv-conditional if="( '[wpv-post-author]' eq '[wpv-current-user]' )" debug="true"]
Author edit post conditional: [toolset-edit-post-link layout_slug="edit-listing" class="edit-post-link"](edit)[/toolset-edit-post-link]
[/wpv-conditional]

Now even if there is a problem with the edit post link shortcode, some content will be written to the page if the conditional is true. This will be helpful to determine the issue(s). Add text information like this to each conditional, then test again. You will see some information printed to the screen. Copy the results and debug information written to the screen for me to review.

PS: Do you still offer those shared desktop sessions?
Yes, you can request a Hangouts-based video call here: https://toolset.com/toolset-support-policy/ask-support-video-call/

OR I could record a screencast if needed.. It probably wouldn't hurt
A screencast is always appreciated, and may be enough to solve the problem without needing to schedule a video call. It takes some time to get those approved and scheduled, and that can cause delays in providing solutions.

PPS: I've tried doing a Duplicator backup but I think WPEngine must block it, it fails
WPEngine has some strict policies regarding duplication software. It's usually more effective to create a database dump file and backup your theme and plugins directories. Then provide a download link where I can find a zip archive of all those materials, and I can work from those instead. I don't think it's necessary just yet, let's go through the main troubleshooting steps first and I'll request that info if it's necessary.

#1092673

I will do that yes.

Could you point me to the full documentation for those shortcode options, such as the debug="true".

Also, is it possible to check if the current user has role of 'Administrator' for example? I could not find anything in your docs.

#1093084

Could you point me to the full documentation for those shortcode options
There is a comprehensive guide to Views shortcodes here:
https://toolset.com/documentation/user-guides/views-shortcodes/
Types field shortcodes are documented here:
https://toolset.com/documentation/customizing-sites-using-php/functions/

Also, is it possible to check if the current user has role of 'Administrator' for example?
Yes the wpv-current-user shortcode can give you access to the current User's role:

role: [wpv-current-user format='meta' info='role']

You can use that shortcode in a conditional.

Also, Access offers inline controls that can help you restrict access to certain content based on User role:
https://toolset.com/documentation/user-guides/access-control-texts-inside-page-content/

My manager let me know you asked to schedule a video call. Can you tell me if that's still needed, and if so, your local timezone? I'll try to find a time that is suitable for everyone and get it scheduled.

#1093196

Hi,

Thanks a bunch.

I had managed to miss that meta Info for the role, wonderful.

We did use Access Control and as far as I know if it set up properly, BUT when it comes to displaying or hiding the link to Edit the form I though this Conditional was needed.

If it's not too much hassle, i would love to try one of those video calls. I figure it's the quickest route to show you through the "logic" we worked out. How would we go about setting that up? It's 14:49 here right now..

#1093233

Will any of these times work for you?
Wednesday 29 August 2018, 10:00am GMT -3
Wednesday 29 August 2018, 10:30am GMT -3
Wednesday 29 August 2018, 11:00am GMT -3

#1093235

Let's aim for Wednesday 29 August 2018, 10:30am GMT -3

#1093236

Okay I just sent the invitation to the email address associated with your account. Please let me know if you have not received it within the hour, or if you need me to resend to another email address.

#1095066

Thank you so much for the quick call this morning. We're almost there..

Now that the user gets validated, we've discovered that when a new person buys a post, and chooses to create an account when paying, that user account is not assigned as the author of the post. I assume it's because the account creation is done after the post creation. Is there some existing solution for this scenario?

#1095069