My site uses DiscourseConnect Provider so Wordpress manages logins to Discourse.
When a user registers in Wordpress, I would like a Discourse user to be immediately created for them and the Discourse activation email sent to them. But that doesn’t seem to happen.
I have checked the “Sync user data” bit in Wordpress settings.
It seems like the description says it will create a Discourse user when they log into to Wordpress. But I don’t see that happening. The discourse user isn’t created until they visit the Discourse site.
Is my integration not working properly? Or am I misunderstanding this description?
I understand now. It is creating a new Discourse user when they “log in” to Wordpress. It’s not creating a new user when they “register” on Wordpress. Our users can register themselves and on registration they are immediately considered logged in. So at that point they are logged in but don’t have a Discourse user.
If they log out of WP and log back in to WP then a Discourse user is created. I just verified that.
We don’t require emails to be verified in Wordpress because it’s a WooCommerce site and it automatically registers them if they make a purchase while not logged in. The first time they visit Discourse after being registered they are getting the address verification email from Discourse.
The problem users are the ones that both:
Register in WP but don’t log out and log back in
Never visit Discourse (which is our support site for the ecommerce site)
Wordpress/WooCommerce treats self-registration as a login - they are considered logged in immediately after they register. Is there any way to make it so a Discourse user is created when they self-register and not just when they log out and log back in?
Hey Ryan, you’re right that the plugin is creating a user after login. Specifically, the plugin is using wp_login hook. There is also a user_register hook in Wordpress, however the reason the plugin doesn’t use that is because this fires immediately after a record is inserted into the Wordpress database, regardless of whether their details (in particular their email) is verified.
To be slightly cheeky, I think the question here might be why doesn’t WooCommerce trigger the wp_login hook if that is the case But, more helpfully, there is likely some other hook or filter that WooCommerce does fire immediately after both registration and login, if that is indeed what it’s doing.
The reason why we haven’t built this into the plugin (as yet), is because, as you might see from your case, there are many different ways users can be created/registered/logged in in Wordpress.
But lets see if we can get your specific case working. First, we need to find a hook that fires immediately after your registration/auto-login is happening. Can you confirm exactly how you have that setup? i.e. Exactly what flow you’re using. The more specific the better, e.g. any documentation you used.
I suspect that WooCommerce is what’s causing the confusion. It looks like automatically being logged in after registration is a WooCommerce feature, not a Wordpress feature. And they intentionally don’t fire the login actions.
I can search for an appropriate WooCommerce hook to use for this. Is there a WP Discourse function I can call or hook I can fire to create the Discourse user if I find the right WooCommerce hook?