Page 1 of 1

Auto Login On PayPal Return?

PostPosted: November 3rd, 2011, 8:44 pm
by ryanseo
Is there a way to edit your return template to automatically log the user in with the username/password details they entered into the PayPal Pro Form registration form so I can use that to log the person in automatically , thus taking them to the set Login Page (in my case, it's the author template which utilizes a number of custom functionality to show the user's posts on the front end, etc)

Re: Auto Login On PayPal Return?

PostPosted: November 3rd, 2011, 9:36 pm
by ryanseo
This has been figured out:

Adding this into your theme's function files will set a cookie for you and automatically log you in after registering and returning back from a successful PayPal membership purchase (since the registration uses built in WP registration functionality):

Code: Select all
function auto_login_new_user( $user_id )
    {
      wp_set_auth_cookie( $user_id, false, is_ssl() );
    }
add_action( 'user_register', 'auto_login_new_user' );


Hope this helps someone who also needs this kind of functionality.

**Note: Not sure if this works with s2member non-pro forms as I'm utilizing the Pro Forms but if it uses the same wp registration functionality then it should absolutely work for non-pro members as well.

Re: Auto Login On PayPal Return?

PostPosted: November 3rd, 2011, 11:08 pm
by Eduan
Okay, glad you solved it!

Re: Auto Login On PayPal Return?

PostPosted: November 4th, 2011, 12:30 am
by Cristián Lávaque
Ryan, that may miss some functionality like the Notifications API, the new user and confirmation emails. Please see this thread: viewtopic.php?f=4&t=14211

I hope that helps. :)

Re: Auto Login On PayPal Return?

PostPosted: November 4th, 2011, 9:04 am
by ryanseo
Cristian,

Thank you very much sir.

Code: Select all
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('urltoredirectto');
        exit();
    }
}


Worked perfectly and I receive notifications like I should be, good eye and thanks again.

Re: Auto Login On PayPal Return?

PostPosted: November 4th, 2011, 2:00 pm
by Cristián Lávaque
My pleasure. :)

Make sure the user gets the emails too (new user and payment confirmation).

Re: Auto Login On PayPal Return?

PostPosted: November 4th, 2011, 2:09 pm
by ryanseo
Yep, they work perfectly as well, thanks for the help on that.

Re: Auto Login On PayPal Return?

PostPosted: November 5th, 2011, 10:33 pm
by Cristián Lávaque
Excellent. :)