Page 1 of 2

automatic redirect to members page after open registration

PostPosted: July 23rd, 2011, 8:27 pm
by glbrent
I have s2member pro. I'm trying to make my open registration form redirect the user to my member page as soon as they register on my site. However, It doesn't seem to do. So right now I have it setup to a thank you page:
Code: Select all
success="https://apazones.com/thankyou"
. The "thank you page" just says thank you and check your email for username/password:

However, what I NEED and was thinking that I could simply pass the login/password variables into the success page redirect so it could still go to the members page like this
Code: Select all
success="https://apazones.com/members/?user_login=%%user_login%%&user_pass=%%user_pass%%"

but that doesn't seem to work either.

I also have Login with ajax running as well. My members page is set to level 0 so it shouldn't be a premission issues if I could pass the newly created variables and automatically login.
I've also tried to let the password be userdefined.
Am I having a plugin conflict or just a coding or redirect conflict?
Thank You

Re: automatic redirect to members page after open registrati

PostPosted: July 25th, 2011, 8:36 pm
by Cristián Lávaque
The default after registration is to have the user login. I wrote a hack to have him logged in automatically after registration and redirected to the page you specify. Here it is:

/wp-content/mu-plugins/s2hacks.php
Code: Select all
<?php
add_action
('ws_plugin__s2member_during_configure_user_registration_front_side', 's2_auto_login_after_registration');
function s2_auto_login_after_registration($vars = array()) {
    wp_set_auth_cookie($vars['user_id'], false, is_ssl());
    wp_redirect(S2MEMBER_LOGIN_WELCOME_PAGE_URL . '?first');
    exit;
}
?>


I hope it helps. :)

Re: automatic redirect to members page after open registrati

PostPosted: July 25th, 2011, 10:44 pm
by Cristián Lávaque
By the way, you can use the first variable in the Login Welcome Page's URL, in a conditional to display a different message for new members.

Code: Select all
<?php if (isset($_GET['first']) { ?>
Welcome new user.
<?php } else { ?>
Welcome returning user.
<?php } ?>


You need a PHP execution plugin for that code to work in a WordPress page. https://wordpress.org/extend/plugins/exec-php/

Re: automatic redirect to members page after open registrati

PostPosted: July 26th, 2011, 12:57 am
by glbrent
wow, thanks Cristian! that's an awesome little hack!!

Re: automatic redirect to members page after open registrati

PostPosted: July 26th, 2011, 2:42 am
by Cristián Lávaque
;)

Re: automatic redirect to members page after open registrati

PostPosted: July 26th, 2011, 8:36 am
by rwilki
i'm getting errors with this code. tried it in template and also in page with exec-php plugin. i'm getting syntax errors. do i also need the hack above?

<?php
add_action('ws_plugin__s2member_during_configure_user_registration_front_side', 's2_auto_login_after_registration');
function s2_auto_login_after_registration($vars = array()) {
wp_set_auth_cookie($vars['user_id'], false, is_ssl());
wp_redirect(S2MEMBER_LOGIN_WELCOME_PAGE_URL . '?first');
exit;
}
?>

I'm not sure where to put this...

Re: automatic redirect to members page after open registrati

PostPosted: July 26th, 2011, 11:51 pm
by Cristián Lávaque
The hack would go in this directory/file (create them if you don't have them) /wp-content/mu-plugins/s2hacks.php

What error are you getting?

Re: automatic redirect to members page after open registrati

PostPosted: August 3rd, 2011, 6:33 pm
by btuk1
Thank you Cristián !

That was really annoying me and your hack works superbly!

I love s2Member, it really is a fantastic script!!!

Re: automatic redirect to members page after open registrati

PostPosted: August 3rd, 2011, 8:13 pm
by btuk1
One problem with the hack is that if you are using the "On Registration" API Notification, the hack seems to overide it and doesn't trigger any custom routines.

A quick look at the code and I think I can just use:

Code: Select all
wp_set_auth_cookie($vars['user_id'], false, is_ssl());
wp_redirect(S2MEMBER_LOGIN_WELCOME_PAGE_URL . '?first');


At the end of my scripts as I pass the UserID any how.

I am not a coder and cookies is out of my realm but I muddle through.

Re: automatic redirect to members page after open registrati

PostPosted: August 4th, 2011, 12:10 am
by Cristián Lávaque
Thanks for the kudos! :)

Are you trying to use the Registration or Signup Notification?

Re: automatic redirect to members page after open registrati

PostPosted: August 4th, 2011, 3:54 am
by btuk1
I am using the Registration Notification

Re: automatic redirect to members page after open registrati

PostPosted: August 5th, 2011, 12:17 am
by Cristián Lávaque
OK. Could you try this for the hack?

Create this dir/file /wp-content/mu-plugins/s2hacks.php
Code: Select all
<?php
add_action 
('ws_plugin__s2member_during_configure_user_registration', 's2_auto_login_after_registration');
function s2_auto_login_after_registration($vars = array()) {
    if (!is_admin() && $vars['processed'] === 'yes') {
        wp_set_auth_cookie($vars['user_id'], false, is_ssl());
        wp_redirect(S2MEMBER_LOGIN_WELCOME_PAGE_URL . '?first');
        exit();
    }
}
?>

Re: automatic redirect to members page after open registrati

PostPosted: August 5th, 2011, 4:39 am
by btuk1
Well done Cristián !

That works exactly as needed.

This is why s2Member amazes me.
It is just such a powerful framework that is incredibly flexible and just look how small and neat the bespoke customization can be.

How on earth this quality is free or such a small price for the Pro version is almost beyond me.

Many thanks Cristián, your knowledge is fantastic.

Re: automatic redirect to members page after open registrati

PostPosted: August 5th, 2011, 10:24 pm
by Cristián Lávaque
Thanks for the kudos! And thanks for confiriming it worked. :)

It was Jason who helped me fixing the notification problem. I didn't know what was wrong. :P

Re: automatic redirect to members page after open registrati

PostPosted: August 5th, 2011, 11:52 pm
by btuk1
Well it's an awesome team.

Thanks to you both!

Re: automatic redirect to members page after open registrati

PostPosted: August 6th, 2011, 12:29 am
by Cristián Lávaque
:)

Re: automatic redirect to members page after open registrati

PostPosted: August 12th, 2011, 2:16 pm
by rwilki
Cristian, thanks to you, I've got this working great. It automatically logs someone in after registration. And thanks to help from Joe, I've managed to have a redirection to protected content after login from Member Options page. Is there a way to do the same thing after registration? In other words, to have the visitor redirected to the protected content upon registration?

Thanks,
Bob

Cristián Lávaque wrote:The default after registration is to have the user login. I wrote a hack to have him logged in automatically after registration and redirected to the page you specify. Here it is:

/wp-content/mu-plugins/s2hacks.php
Code: Select all
<?php
add_action
('ws_plugin__s2member_during_configure_user_registration_front_side', 's2_auto_login_after_registration');
function s2_auto_login_after_registration($vars = array()) {
    wp_set_auth_cookie($vars['user_id'], false, is_ssl());
    wp_redirect(S2MEMBER_LOGIN_WELCOME_PAGE_URL . '?first');
    exit;
}
?>


I hope it helps. :)

Re: automatic redirect to members page after open registrati

PostPosted: August 12th, 2011, 3:41 pm
by Cristián Lávaque
Thanks for the kudos, you're very welcome. :)

You can just change the URL in the wp_redirect line so instead of the Login Welcome he goes to the other protected page.

Re: automatic redirect to members page after open registrati

PostPosted: August 12th, 2011, 4:23 pm
by rwilki
Cristian, this is a dynamic variable depending upon what post someone clicked on. So how would I know what the url would be? My other redirect from the login uses a javascript shortcode to

===
$post = preg_split('/-/', $_GET['s2member_seeking']);
echo "/?p=" . $post[1];
===

and then on the member options page, I have this code

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

So a visitor upon clicking a link > logging in > is redirected to protected post. I just want the same for the registration process, after logging in, is this possible?

Re: automatic redirect to members page after open registrati

PostPosted: August 12th, 2011, 5:30 pm
by Cristián Lávaque
Yeah, I understand. I don't know how to do that with JS, you should ask Joe who gave you the login redirect tip.

What I suggested for the registration was to save in a cookie/session the MOP var or the URL to the page that bounced him, so you have it available when you want to redirect with my hack. E.g. wp_redirect($_COOKIE['URL_to_page_that_bounced_him']);

Re: automatic redirect to members page after open registrati

PostPosted: August 15th, 2011, 2:20 pm
by Cristián Lávaque
Here's an update to the hack, to fix a problem with new user emails not being sent to the user or admin.

Create this dir/file: /wp-content/mu-plugins/s2hacks.php
Code: Select all
<?php
add_action
('ws_plugin__s2member_during_configure_user_registration', 's2_auto_login_after_registration');
function s2_auto_login_after_registration($vars = array()) {
    if (!is_admin() && $vars['processed'] === 'yes') {
        wp_new_user_notification($vars['user_id'], $vars['pass']);
        wp_set_auth_cookie($vars['user_id'], false, is_ssl());
        wp_redirect(S2MEMBER_LOGIN_WELCOME_PAGE_URL . '?first');
        exit();
    }
}
?>


Thank you Jason for your help with this again.

Re: automatic redirect to members page after open registrati

PostPosted: August 15th, 2011, 4:23 pm
by glbrent
SUBLIME! Thank you Cristian!

Re: automatic redirect to members page after open registrati

PostPosted: August 16th, 2011, 11:39 am
by rwilki
Cristián Lávaque wrote:Yeah, I understand. I don't know how to do that with JS, you should ask Joe who gave you the login redirect tip.

What I suggested for the registration was to save in a cookie/session the MOP var or the URL to the page that bounced him, so you have it available when you want to redirect with my hack. E.g. wp_redirect($_COOKIE['URL_to_page_that_bounced_him']);


Thanks for replying. I'll keep trying to configure this. I appreciate your followups. Your support is A+!

Re: automatic redirect to members page after open registrati

PostPosted: August 17th, 2011, 3:01 am
by Cristián Lávaque
Thanks for the kudos guys. I'm glad to help. :)

Re: automatic redirect to members page after open registrati

PostPosted: August 17th, 2011, 3:10 am
by rwilki
Cristian, has anyone posted any examples of MOP variables for us to learn from? Almost all of the code is for logged in visitors. I can't get it to work for users seeking certain level content who are not logged in.

Am using
Code: Select all
<?php } elseif { ($_GET['s2member_level_required'] === '0') ?>
By registering now...
<?php } elseif { ($_GET['s2member_level_required'] === '1') ?>
Premium Access Pass...
<?php } ?>


But it's not filtering anything. It's showing both areas of content regardless of which level content is required. I'm testing this as an unlogged in visitor...