Creating Discourse accounts during user import

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:
https://github.com/scossar/wp-discourse-wishlist-member/blob/master/lib/discourse-wishlist-utilities.php#L164

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.

3 Likes