Auto Login after Registration to same page (Refresh)

Hey,

I am using the [s2If is_user_not_logged_in()] shortcode on 2 of my pages which require a login. This shortcode is around a login and registration form. After the shortcode is closed the normal content gets displayed (when the user is logged in).

Now what I want to accomplish is that after registration, the user gets automatically logged in and redirected to the current url he is already on (which works already thanks to the well documented s2member). For ‘redirect_to_automatic’ I filled in get_permalink(), which also kinda works, it basically refreshes the page. But the problem is it still displays the content between the [s2If is_user_not_logged_in()] shortcode, but this time with the login form gone (shows edit profile and the other stuff). If I refresh again, my browser asks me if I want to resubmit the form, then the content for logged in users is displayed. So basically it needs another refresh to notice that the user is actually logged in already.

I was wondering if there is a better solution to this. The registration form currently has no success url, as this is set my the s2-auto-login.php to the current url as described above.

Cheers

Are you caching that page? If so, you might want to try excluding that URI.

I did exclude these pages from caching, that didn’t change it however. The page still requires a fresh and another form submission to show the content for logged in users.

What code are you using for the auto-login?

The first example here:

That’s your problem, and demonstrates why you should search before posting.

You need to use an amended version of that code, which I pasted here: Sign in the new user after Checkout

Ok first of all, thank you for the link, it partially solved the problem. I don’t think I would have seen the difference (2 lines) between the knowledgebase code and the one you linked.

I understand from the code it redirects to the membership options page. This is useful for the registration form which is on my membership area, they are indeed supposed to get redirected to that page.
I have a second reg form on /checkout/ though, I was hoping for a way where user registering on that specific form get redirected to /checkout/ again, where then the checkout content gets displayed. Is there a way to differ between those 2 reg forms and their respective redirects?

I haven’t tried this, but I’d guess that a conditional is what you want. Something like

if (is_page(name or id of page)) {
//redirect to one place
} else {
//redirect to another
}
1 Like

I tried what you suggested and noticed that it always redirects to the membership options page, even if I remove the wp_redirect and the redirection action looks like this:

function _s2_auto_login_after_registration() // Pro Form redirection handler.    
{
$vars = $GLOBALS['_s2_auto_login_after_registration_vars'];
c_ws_plugin__s2member_login_redirects::login_redirect($vars['login'], $vars['user']);

exit;
}

So the wp_redirect which is normally in there doesn’t seem to do anything.

Then you have a different problem on your site, because that code should never redirect to that. What’s the relevant URL?

The registration form can be found here: activemoves.de/mitgliederbereich, and the second one I am talking about is on /checkout.

The /checkout/ page doesn’t have s2Member running on it.

On both pages, you have Autoptimize running. I’d try deactivating it. You also have a javascript file with an utterly garbled name loading from Google. I have no idea what that is, but it looks odd to me.

If you don’t have people set their password during registration (note, they won’t recive the welcome e-mail if you have them set their own password. ) then you are looking at a two step process. The first step is the registration. Then they get e-mailed a notice with a link to set the password. On that page they see a “reset” password form. and enter in their password of choice. THEN they can log in. So the process is: registration and then password set.

What you might need to do is to set a cookie and then check if a person has been logged in before. Or use HTML5 session data. Either way you are storing the url and the system just needs to check if that data exists. If it does, go to that page and clear the cookie and/or data. So when they logged in for the first time after setting up an account they will go to the page they were previously on. I know it can be done this way but as to exactly how, I wouldn’t know until I studied it further.

@DrewTheGeek People do actually set the PW during registration.

@KTS915 It is running there, in between the user is not logged in shortcode is a login and registration form. You might have to put something into the basket from the shop to see the login/reg showing up. Otherwise /checkout/ doesn’t display anything s2member related.

Regarding the JS file, which one do you mean exactly? I can only see analytics and adsbygoogle.

Yes, you’re right.

The one that begins SLZ6djv ...

But you’re still running Autoptimize. And I would take off the modal pop-up too while you test, in case that’s the cause.

I fixed it, using a different modal window (which does not place its contents on every page into the body), it was possible to create 2 different reg forms with different success urls. Thanks for your help!