Creating Discourse accounts during user import

AI-generated summary

In a discussion titled “Creating Discourse accounts during user import” under the WordPress category, epiphron asks whether it’s possible to pre-create Discourse accounts for users imported from a previous site, before they log in via WordPress SSO — primarily so they can receive forum digest emails immediately. simon initially suggests that enabling the ‘Create Discourse User on Login’ setting in WP Discourse would suffice, as accounts are auto-created upon first login. However, recognizing the need for pre-creation, simon later recommends using Discourse’s sync_sso route, which allows syncing user data before login, and links to a guide: Sync SSO User Data with the sync_sso Route. epiphron thanks simon for the quick response and plans to try the suggested approach to meet the client’s requirement for immediate digest email delivery.

Hi, all. I’ve just launched a new WordPress website using the excellent WP Discourse plugin for SSO and discussion.

Everything is working smoothly, but I’ve had to import a lot of user accounts from the client’s previous website. These users haven’t all logged in to the new website yet, but the client has asked whether they can be added to the Discourse forum as users, before logging in for the first time and generating their account via the SSO process.

Is it possible to create these accounts on Discourse without having the users login to WordPress and go through the SSO process?

Is the situation that the users exist on the current site, but have never logged into the WordPress site? If so, I’m not sure why you need to create Discourse accounts for them before they have logged in. If you enable the wp-discourse ‘Create Discourse User on Login’ setting, accounts will be created for them when they first login to your site.

If you really need to do it, you can create Discourse users from WordPress users through the API. Here’s an example of how to do it:
wp-discourse-wishlist-member/lib/discourse-wishlist-utilities.php at master · scossar/wp-discourse-wishlist-member · GitHub

Edit: for sites using SSO, the best way to add users to Discourse before they login is to use the sync_sso route: Sync DiscourseConnect user data with the sync_sso route.

Hi @simon, thanks for the speedy reply. It’s mainly for the forum digest emails that get sent out. My client wants the website users to receive these emails without first having to sign in and access the forum.

Thanks for the link to that function, I’ll give it a go.