Can anybody help with, what should be, a simple redirect issue in WordPress.
I have a couple of pages that are part of a sign-up process that I want to ‘hide’ unless accessed as part of that process.
As an example, the page ‘/join/payment-setup/’ needs to be inaccessible unless a visitor has come from the ‘/join/’ page – just a simple redirect to the ‘/join/’ page would suffice.
2
Answers
I’m not a WordPress expert, but with a quick run through the documentation, I would probably do it with a mix of using
sessions
,wp_get_referer()
, andwp_redirect()
.wp_get_referer
if it matches the/join/
page. If it does, save some session status for later use. This should be checked on every page to ensure it also gets reset. Notice that with this setup, if the user refreshes the page in thepayment-setup
page, they will lose access. So you would have to add some logic to deal with that.page
you want to control the access, check if a user is allowed to go there, similarly to preventing access before the user signs in. If the user has not come from the right page, re-direct them to the correct page usingwp-redirect
and exit the code.Instead of checking the unreliable (and fakeable) referer information, you could do this:
/join/
, store$_SESSION['allow_join'] = true;
/join/payment-setup/
, checkif ($_SESSION['allow_join'] == true)
, otherwise redirect user to the/join/
page.