1

I have a Wordpress site where there is a restricted page, and if the user navigates to this page but is not logged in, they get sent to a sign-up page.

If they log in using this form, they do get logged in but they stay on the same page showing the login form.

I want them to be able to log in and then when the page re-loads, they get sent to whichever restricted page they were previously trying to view.

In my page template I have used:

<?php if(!is_user_logged_in()) { ?>
show login form
<?php } else { ?>

<?php } ?>

And its the blank space where I need to put something to say if they ARE logged in then go back to previous page (before they got redirected for not being logged in).

Thanks

Adrian
  • 285
  • 2
  • 14
  • 1
    when redirecting the user to the login form redirect with a url like "login?origin=foo", and when submitting the login form just send the user to the origin page. – bitoiu Jun 22 '14 at 18:21
  • Unfortunately it's the wordpress membership system plugin which is restricting the page that redirects the user to a page of my choice (which is the "sign-up" page) so the URL that the user goes to is generated by the plugin. – Adrian Jun 22 '14 at 18:26

1 Answers1

0

If I'm understanding your question, then I think the window.location javascript property is what you're looking for. Use it like so:

window.location = "http://myredirect.com"

See this post's top answer if you want some more information.

If you really want to use the history back button, you can take a look at history.back() as referenced in this question and top answer.

Community
  • 1
  • 1
The Velcromancer
  • 437
  • 3
  • 10
  • I have 3 different pages which are restricted, all of which send the user to the sign-up page if they are not logged in. So the code that I use cannot have a fixed URL in as they just need to go back to which 1 of the 3 they have come from. – Adrian Jun 22 '14 at 18:28
  • The `history.back()` function might be what you're looking for (basically just clicks 'back' in the user's browser). Alternatively, you could include the source page url in the request from the user to the server, and then use that information in the redirect. – The Velcromancer Jun 22 '14 at 18:33
  • I've just found another topic which suggested using: window.location.replace(document.referrer) this worked, but put the page in a loop as it sends me back but not far enough, the redirect still kicks in, I must have to go back 2 pages, is this possible using that? – Adrian Jun 22 '14 at 18:37