Page 1 of 1

Redirect based on URL variable...

PostPosted: October 26th, 2011, 10:55 am
by rwilki
This is a new question based on an old thread. With the help of another forum user (joeboydston) I was able to make s2Member function more intuitively.

Basically, when a reader clicks on a level #0 or #1 post, they either have to be logged in to the correct level or register/pay. Once a reader logged in, they were redirected to the protected post rather than the Membership Options page.

The hack uses the sidebar-login plugin and the shortcode-exec-php plugin to make it function. There have been a lot of updates to s2Member since I last posted in this forum but I'd like some help with a tweak. I would like to know if I can use the redirect functionality without having to use the login sidebar. In other words, is there a way to pass on the variable in the protected url through the wp login page? Here is my code. Any help would be great. I just find it so annoying that the Membership Options page is mandatory.

Code: Select all
<script type="text/javascript">// <![CDATA[
/* <![CDATA[ */
    jQuery.noConflict();
    jQuery(document).ready(function($){
       $(".redirect_to").val("[s2_redirect]");
    });
/*  */
// ]]></script>

Re: Redirect based on URL variable...

PostPosted: October 26th, 2011, 11:22 pm
by Cristián Lávaque
Sorry, I don't know JavaScript, so I'm not sure how that hack works.

I can tell you that if you add the redirect_to variable to the URL for the login page, that's where the person will be take after login.

http://example.com/login.php?redirect_t ... rson-to-go

Re: Redirect based on URL variable...

PostPosted: October 27th, 2011, 8:38 am
by rwilki
Thanks Cristian. That's an interesting approach. I'm wondering how I can do this in a more dynamic method.

My url for a protected article might be:

http://www.mydomain.com/news-article-may-15-2011 basically, I want the redirect to go to this article once people have registered or logged in. Essentially bypassing the MO page. I don't see how I could hardcode this in every link on my site since the url is created by my publishing of the post and I would have to manually do this for every article...

Re: Redirect based on URL variable...

PostPosted: October 27th, 2011, 11:16 pm
by Cristián Lávaque
Could you show me where your login link/form is? You can send it via the contact form if you don't want to make it public. http://s2member.com/contact

I'm guessing you want to have this return to the page either when the person clicks the login link on it, or if he gets taken to the Membership Options and you remind him to login to view the page, right?

You can use variables in both cases to create the redirect_to value. When in the MOP, you have the MOP vars which will include the post/page that bounced the user. WP Admin -> s2Member -> API / Scripting -> Membership Options Page Variables

So you can do something like:

Code: Select all
<?php $p = explode('-', $_GET['s2member_seeking']); ?>
<a href="<?php echo wp_login_url('/?p=' . $p[1]); ?>" title="Login">Login</a>


http://codex.wordpress.org/Function_Ref ... _login_url

I hope this helps. :)

Re: Redirect based on URL variable...

PostPosted: October 31st, 2011, 9:18 am
by rwilki
Thanks for this idea Cristian! I'm sorry for my delayed reply. I'll try this out and send you the login link if I can't get it to work. Your support is incredible!

Thanks,
Bob

Re: Redirect based on URL variable...

PostPosted: October 31st, 2011, 11:30 pm
by Cristián Lávaque
You're welcome! Thanks for the kudos. :)