PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Go to previously viewed page after login

s2Member Plugin. A Membership plugin for WordPress®.

Go to previously viewed page after login

Postby jhg03 » August 31st, 2010, 11:15 am

There is a login link on every page of my website. At any time, if a user decides to login is there a way to redirect them back to the page they were previously on (instead of redirecting them to the specified "members welcome page"?

Advice appreciated, thank you!
User avatar
jhg03
Registered User
Registered User
 
Posts: 19
Joined: August 31, 2010

Re: Go to previously viewed page after login

Postby Jason Caldwell » August 31st, 2010, 7:03 pm

Yes, this would need to be built into your theme, or possibly into a Login Widget if you prefer. The s2Clean theme that comes with s2Member Pro handles this automatically.

Otherwise, here is how it's done.
Code: Select all
http://example.com/wp-login.php?redirect_to=http://example.com/a-particular-page

So after logging in, they'll be automatically redirected to the redirect_to value.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Go to previously viewed page after login

Postby jhg03 » August 31st, 2010, 8:49 pm

Thank you Jason for your reply and solution. It's close but not quite what I was looking for though. Let me see if I can explain this better.

If they were on the About page and logged in, I would want them to return to the About page.
If they were on the Services page and logged in, I would want them to return to the Services page.
(And I have over 50 pages and a login link is on all my posts, so assigning specific values to each of the links isn't an option ;) )

Instead of directing them to one specific page is there perhaps some other code I could include that would say, take them a couple steps back to where they were on my site previously. Just one string that I could use in all my login links?

Sorry for the confusion.
User avatar
jhg03
Registered User
Registered User
 
Posts: 19
Joined: August 31, 2010

Re: Go to previously viewed page after login

Postby Jason Caldwell » August 31st, 2010, 11:41 pm

Hi there. Thanks for reporting back.

Here is how I would handle it:
Code: Select all
/wp-login.php?redirect_to=<?php echo rawurlencode($_SERVER["REQUEST_URI"]); ?>

So you will need some PHP for this. That PHP tag:
<?php echo rawurlencode($_SERVER["REQUEST_URI"]); ?>
will automatically insert a link to the current page. So clicking that link from anywhere on your site, will always redirect a visitor back to the page they were viewing before they logged in.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Go to previously viewed page after login

Postby jhg03 » September 9th, 2010, 9:59 am

This looks like exactly what I need, but I'm not sure how I should implement it in my code. (my php knowledge is very limited at the moment) I have added the php into the link but am sure I am doing it all wrong as it is not functioning properly.

Here's all my code: (login link in question is at the bottom)

Code: Select all
if (is_user_logged_in() && current_user_can("access_s2member_level4")){
    echo '<p class="login-links"><span class="login-greeting">Welcome back, ';
    echo S2MEMBER_CURRENT_USER_FIRST_NAME;
    echo '</span><br /><a href="
http://www.workplacecoachinstitute.com/cmd.php?cmd=cart">View Cart</a> <span class="login-spacing">|</span> <a href="http://workplacecoachinstitute.com/?s2member_profile=1">Profile</a> <span class="login-spacing">|</span> <a href="http://workplacecoachinstitute.com/wp-login.php?action=logout">Logout</a></p>';
} else {
    return '<p><a href="
http://www.workplacecoachinstitute.com/cmd.php?cmd=cart">View Cart</a> <span class="login-spacing">|</span> <a href="http://workplacecoachinstitute.com//wp-login.php?redirect_to=<?php echo rawurlencode($_SERVER["REQUEST_URI"]); ?>">Login</a></p>';
}


Thank you for your assistance.
User avatar
jhg03
Registered User
Registered User
 
Posts: 19
Joined: August 31, 2010

Re: Go to previously viewed page after login

Postby Jason Caldwell » September 9th, 2010, 10:27 am

Hi there. Thanks for writing in.
Try this instead. You were really close, just a couple of things needed tweaking.
Code: Select all
<?php
if 
(is_user_logged_in () && current_user_can ("access_s2member_level4"))
    {
        echo '<p class="login-links">';
        echo '<span class="login-greeting">Welcome back, ' . S2MEMBER_CURRENT_USER_FIRST_NAME . '</span><br />';
        echo '<a href="http://www.workplacecoachinstitute.com/cmd.php?cmd=cart">View Cart</a> <span class="login-spacing">|</span> ';
        echo '<a href="http://workplacecoachinstitute.com/?s2member_profile=1">Profile</a> <span class="login-spacing">|</span> ';
        echo '<a href="http://workplacecoachinstitute.com/wp-login.php?action=logout">Logout</a>';
        echo '</p>';
    }
else
    {
        echo '<p>';
        echo '<a href="http://www.workplacecoachinstitute.com/cmd.php?cmd=cart">View Cart</a> <span class="login-spacing">|</span> ';
        echo '<a href="http://workplacecoachinstitute.com/wp-login.php?redirect_to=' . rawurlencode ($_SERVER["REQUEST_URI"]) . '">Login</a>';
        echo '</p>';
    }
?> 
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Go to previously viewed page after login

Postby jhg03 » September 9th, 2010, 10:50 am

Perfect! Thank you very much!!!
User avatar
jhg03
Registered User
Registered User
 
Posts: 19
Joined: August 31, 2010

Re: Go to previously viewed page after login

Postby Jason Caldwell » September 10th, 2010, 1:37 am

You're very welcome. Glad I could help.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Go to previously viewed page after login

Postby jhg03 » September 21st, 2010, 10:13 pm

Just discovered the redirect code works if someone is logging in with administrator privileges. However, it doesn't work if they have an s2Member level 4 role - just takes them back to the homepage of the website.

Any fix? - Thanks!
User avatar
jhg03
Registered User
Registered User
 
Posts: 19
Joined: August 31, 2010

Re: Go to previously viewed page after login

Postby Guest » September 26th, 2010, 8:43 am

Is there a way how to stop s2member from redirecting users after login at all? I have a different login/redirect system - s2member hijacks this and forces users to go to frontpage even if there is no login welcome page setup in s2member config.
Guest
Guest User
Guest User
 

Re: Go to previously viewed page after login

Postby drbyte » September 26th, 2010, 10:36 pm

<a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">anything in here</a>

BUT

If you are using the Login Welcome Page to redirect members away from the admin backend then the code above or any code will not work. It will simple redirect them back to the welcome page

You can disable the redirection mode but that defeats the the whole purpose of protecting the backend of your site.

Sam
User avatar
drbyte
Experienced User
Experienced User
 
Posts: 269
Joined: May 6, 2010

Re: Go to previously viewed page after login

Postby jhg03 » September 28th, 2010, 10:17 am

Anyone?
User avatar
jhg03
Registered User
Registered User
 
Posts: 19
Joined: August 31, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron