Skip Navigation

[Resolved] Automatic Redirect if Current User ID does not match Post ID

This support ticket is created 2 years, 9 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 Adrian Robbins 2 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2304317

In the Content Template, we need to have a redirect to a page if the logged in user ID does not match the post ID.

It is essential that a logged in user ID (client) can only ever see their own Post ID (booking), and if they try and change the post ID, they see the page we have created.

Just now we use this conditional statement:

<!-- wp:html -->
[wpv-conditional if=" ( ( '[wpv-current-user info='id']' ne '[wpv-post-author format='meta' meta='ID' ]' ) ) "]<div class="jump" id="details">
<h2 class="general-page-content">Page Unavailable</h2>
<hr class="general-page-content">
<div class="general-pages">
<p class="general-page-content">
Please note you can only view your own bookings and muct be logged in with your unique booking reference.<br><br>Please click here to return to the previous page or hidden link">click here to return to the login page. </p>
<p class="general-page-content">Thank you</p>
</div></div>
[/wpv-conditional]
<!-- /wp:html -->

Which dynamically displays the messahe with a couple of links.

However the menu does not work and also the logo (home page) has been disabled, and therefore it could cause confusion. Because if the logged in user ID and Post ID match the entire content template is displayed and then the menu anchor points work correctly.

So, we would like to just redirect to hidden link with a redirect shortcode to replace the code we are using above.

This way, there is a common page for everything on the WebApp if the user and post ID are a mismatch.

#2304649

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

If you just want to redirect the user when current loggedin user ID does not match the post author ID, what if you try to use the WordPress standard hook: template_redirect
- https://developer.wordpress.org/reference/hooks/template_redirect/

You can adjust the code as required.

#2304767

Hi Minesh

Thanks for getting back to me, and my understanding is that because we are wanting the 'redirect' from within a Toolset Content Template and activated via a conditional statement, we need a Toolset Shortcode Redirect, which is linked to a bit of code in the functions.php file? We can then add the shortcode in place of the message at the top of the Content template.

So, the scenario we have is that a user, say 221234 (for simplicity we are using their event booking reference as their username/ID) logs in correctly and checks their booking, which is post 221234 - this is all OK and what we'd expect.

However they decide to change the browser URL to another booking ID, say 221533.

We currently block them from doing this and with a conditional statement display the message at the top of the Content Template code.

However doing it this way, still displays the logo and mobile menu, which now doesn't work, because the 'anchor' points are not loaded.

So, what we want to do is 'redirect' them to /page-unavailable/ which does not have the menu (blank header) and and not sure the WP Standard Hook will work in this scenario because it is not linked to he Toolset Content Template.

Hopefully this is doable.

Kind regards
Ade

#2304783

Minesh
Supporter

Languages: English (English )

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

So, as I understand:

When the following condition satisfies, you want to add/call the shortcode within it and that shortcode should redirect user to the desired page:

[wpv-conditional if=" ( ( '[wpv-current-user info='id']' ne '[wpv-post-author format='meta' meta='ID' ]' ) ) "]
[a-shortcode-to-redirect-to-your-desired -age]
[/wpv-conditional]
#2304803

Hi Minesh

That's exactly what we want to do, and the redirect page is hidden link

So, if logged in as 221234, they see hidden link

However if they change to hidden link, why still logged in as 221234. the user ID and post ID no longer match and they redirect to hidden link

Hopefully it's doable.

Kind regards
Ade

#2304811

Minesh
Supporter

Languages: English (English )

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

What if you install and activate the following plugin:
- https://wordpress.org/plugins/shortcode-redirect/

And then just add the redirection shortcode within the conditional shortcode as given under:

[wpv-conditional if=" ( ( '[wpv-current-user info='id']' ne '[wpv-post-author format='meta' meta='ID' ]' ) ) "]
[redirect url='<em><u>hidden link</u></em>' sec='1'] 
[/wpv-conditional]
#2304815

My issue is resolved now. Thank you!