• Resolved meglos42

    (@meglos42)


    Hi,

    Is it possible to automatically redirect back to the original blocked page after logging in via the main Log In page?
    I don’t want to have log in forms on all blocked pages/posts, so I just have a link to the log in page. However, I’d like the user to be redirected back to the page they came from when they log in. Is this possible?

    Many thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    The WP-Members login does accept the redirect_to parameter through a query string just like the wp-login.php does. So as long as you generate your links with a return path, yes it can redirect back to the page they were on. For example:

    http://mysite.com/my-login/?redirect_to=http://mysite.com/original-page/

    There is a redirect function that you could use, wpmem_redirect_to_login() which will redirect as well as include the return path.

    Thread Starter meglos42

    (@meglos42)

    Thanks Chad,

    Using the “?redirect_to=http://mysite.com/original-page/” option works perfectly! However I’d like to avoid having to manually set this on every protected page as there are a lot of them.

    I’ve looked at the wpmem_redirect_to_login() but I can’t seem to get it configured to work – it doesn’t direct users back to the page they came from, but just stays on the Log In page, with the “You are Logged in as xxx” message.

    Is there any advice you can give me so as I can just use the same http://mysite.com/my-login link on all the protected pages?

    • This reply was modified 9 years, 3 months ago by meglos42.
    • This reply was modified 9 years, 3 months ago by meglos42.

    perhaps if u gave ur website’s url, we could see just what u r talking about…normally, a blocked page says

    This content is restricted to site members. If you are an existing member, please log in. New users may register below.

    so how do u “just have a link to the log in page.”?

    • This reply was modified 9 years, 3 months ago by airdrummer.
    Plugin Author Chad Butler

    (@cbutlerjr)

    The wpmem_redirect_to_login() function automatically handles the return redirect. You don’t have to configure anything for it. But the way to use this is to redirect the user, not use a link to the login page.

    Thread Starter meglos42

    (@meglos42)

    Thanks Chad

    @airdrummer – we have code on the (unblocked) posts on our home page similar to this –

    Here is some unblocked content that anyone can read.
    [wpmem_logged_in]and here is a bit of protected content hidden from view to everyone that is not logged in[/wpmem_logged_in]
    [wpmem_logged_out]here is a link to the login page that is only visible to those who are not already logged in[/wpmem_logged_out]
    And here is a bit more unblocked content for everyone.

    We also have this on several pages thoughout the site with a mixture of blocked and unblocked content.

    So what we want is for people to be able to click that link to log in (a form on the post is too much). Once they have logged in we’d like them to be sent back to the page they came from.

    ok hadn’t thot of protecting just bits&pieces of a page, rather than a whole page…perhaps u could add a redirect hook to the referer:

    $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';

    see http://rocketgeek.com/plugins/wp-members/docs/filter-hooks/wpmem_login_redirect/

    • This reply was modified 9 years, 3 months ago by airdrummer.
    Thread Starter meglos42

    (@meglos42)

    @airdrummer – thanks, not sure how to use that (still learning functions etc.) but I’ll see if I can puzzle it out.

    Plugin Author Chad Butler

    (@cbutlerjr)

    In your shortcode example, you could use the [wpmem_loginout] shortcode to generate a link. It generates a link to log in or out depending on the user’s current state, but since you’re using it within the [wpmem_logged_out] shortcode, it would only be seen when in the logged out state (linking to the login form).

    The resulting link from this shortcode includes a return path.

    You can specify specific text for the link with the login_text attribute:
    [wpmem_loginout login_text=”Sign In Here”]

    http://rocketgeek.com/plugins/wp-members/docs/shortcodes/other-shortcodes/

    There a two similar shortcodes coming in the 3.1.7 release: [wpmem_login_link] & [wpmem_reg_link] – both will include a return path.

    Thread Starter meglos42

    (@meglos42)

    Thanks Chad! You’ve hit the nail on the head – this works perfectly.
    Don’t know how I didn’t see this before, your help much appreciated.

    • This reply was modified 9 years, 2 months ago by meglos42.
    Plugin Author Chad Butler

    (@cbutlerjr)

    No problem – glad that worked out.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Login Redirect Query’ is closed to new replies.