# 合并现有的 Discourse 和 WP 用户列表

**URL:** <https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334>\
**Category:** WordPress\
**Created:** [2019年四月17日 18:25 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334 "2019-04-17T18:25:27Z")\
**Posts on this page:** 18\
**Page:** 2

<div class="post-metadata">

**Author:** ![nefibach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nefibach/32/138703_2.png) [@nefibach](https://meta.discourse.org/u/nefibach)\
**Post date:** [2019年四月23日 19:24 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/21 "2019-04-23T19:24:54Z")

</div>

Thanks, Stephen, that’s really good to know!

---

<div class="post-metadata">

**Author:** ![dylanb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dylanb/32/139102_2.png) [@dylanb](https://meta.discourse.org/u/dylanb)\
**Post date:** [2019年四月23日 21:16 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/22 "2019-04-23T21:16:07Z")

</div>

> [@nefibach](#):
>
> Dylan: Sorry, this is a bit of a tangent, but how do you find Paid Memberships Pro? I bought Memberpress (they don’t do a free or trial version) and whilst it’s functional, it is a bit clunky. I’d love to hear your experience of Paid Memberships Pro!

I’d go with solid. It does the trick but there are some weird fluky things about it overall. My integration with Discourse is one of the primary things that I need to improve. Would be happy to exchange some DMs if you have questions.

---

<div class="post-metadata">

**Author:** ![nefibach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nefibach/32/138703_2.png) [@nefibach](https://meta.discourse.org/u/nefibach)\
**Post date:** [2019年四月23日 21:45 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/23 "2019-04-23T21:45:02Z")

</div>

Thanks! I’ve had a poke about this afternoon, and I think it might take just a bit too much fiddling with the PHP than I am comfortable with!

---

<div class="post-metadata">

**Author:** ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)\
**Post date:** [2019年四月23日 21:57 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/24 "2019-04-23T21:57:38Z")

</div>

Adding the linked code to your theme’s function.php is pretty straightforward. Is there anything else you need to implement?

---

<div class="post-metadata">

**Author:** ![dylanb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dylanb/32/139102_2.png) [@dylanb](https://meta.discourse.org/u/dylanb)\
**Post date:** [2019年四月23日 22:48 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/25 "2019-04-23T22:48:33Z")

</div>

> [@simon](#):
>
> Users who created their WordPress accounts prior to enabling SSO with [WP Discourse](https://github.com/discourse/wp-discourse) will be considered to have valid email addresses. The only issue with using non-default registration systems once SSO has been enabled is that user’s email addresses will be marked as invalid. The plugin supplies a hook that you can use to validate your user’s email addresses. Using the hook requires adding a few lines of code to your site. There are details about how to use it here: [How to turn off Discourse email verification?](https://meta.discourse.org/t/how-to-turn-off-discourse-email-verification/75365).

So the easiest method seems to be to just disable email verification if I want to make things straightforward. The downside to that would be that people could “hijack” someone’s account if it is already existing and they sign up for WordPress using the existing email, right?

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2019年四月23日 23:39 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/26 "2019-04-23T23:39:34Z")

</div>

> [@dylanb](#):
>
> The downside to that would be that people could “hijack” someone’s account if it is already existing and they sign up for WordPress using the existing email, right?

Yes, that’s the risk. If your WordPress registration process allows users to register and login to your site without having to confirm their email address, then users can signup with any email address that doesn’t already exist in your WordPress database.

In terms of SSO, the main risk in marking unverified email addresses as verified is that an account that exists on your Discourse site that is not yet associated with a WordPress account could be taken over.

---

<div class="post-metadata">

**Author:** ![nefibach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nefibach/32/138703_2.png) [@nefibach](https://meta.discourse.org/u/nefibach)\
**Post date:** [2019年四月25日 14:28 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/27 "2019-04-25T14:28:29Z")

</div>

I looked at a couple of the add-ons that I’d need, and at first glance they seem a bit more complex to install than I’m comfortable with. Given that I’ve already paid for Memberpress, PMP would have to be significantly better than Memberpress to make it worth switching and paying again, and I’m not quite sure that it is!

---

<div class="post-metadata">

**Author:** ![dylanb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dylanb/32/139102_2.png) [@dylanb](https://meta.discourse.org/u/dylanb)\
**Post date:** [2019年四月25日 14:45 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/28 "2019-04-25T14:45:40Z")

</div>

Would it make any sense to “import” Discourse users that don’t exist into WordPress before enabling SSO so that all they have to do is reset their password?

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2019年四月25日 17:01 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/29 "2019-04-25T17:01:39Z")

</div>

Yes, importing your Discourse users to WordPress prior to enabling SSO would solve the email verification issue. I’d like to find a more straightforward way of dealing with the issue though.

---

<div class="post-metadata">

**Author:** ![nefibach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nefibach/32/138703_2.png) [@nefibach](https://meta.discourse.org/u/nefibach)\
**Post date:** [2019年五月1日 16:01 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/30 "2019-05-01T16:01:56Z")

</div>

So, another question:

At the moment, when a user subscribes, they are automatically added to a Members group in Discourse to give them access to our locked categories.

So when a user cancels their subscription in Memberpress, is it possible for that to be passed through to Discourse to remove them from the Members group, so that they can only access the public content?

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2019年五月1日 16:32 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/31 "2019-05-01T16:32:09Z")

</div>

> [@nefibach](#):
>
> So when a user cancels their subscription in Memberpress, is it possible for that to be passed through to Discourse to remove them from the Members group, so that they can only access the public content?

There are a couple of ways that users can be added to and removed from groups. The easiest way to do it is to use the `add_groups` and `remove_groups` SSO parameters. That approach is outlined here: [Bring over permission level from WordPress MemberPress - #2 by simon](https://meta.discourse.org/t/bring-over-permission-level-from-wordpress-memberpress/78074/2). The issue with this approach is that it requires users to log out and log back in again before their group memberships will get updated.

The other approach is to use the `add_user_to_discourse_group` and `remove_user_from_discourse_group` functions that are outlined in this topic: [Manage group membership in Discourse with WP Discourse SSO](https://meta.discourse.org/t/managing-discourse-group-membership-with-wp-discourse/74724). The benefi of that approach is that it’s not dependant on the user logging out - their membership levels will be changed as soon as the functions are called.

---

<div class="post-metadata">

**Author:** ![nefibach](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nefibach/32/138703_2.png) [@nefibach](https://meta.discourse.org/u/nefibach)\
**Post date:** [2019年五月1日 17:16 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/32 "2019-05-01T17:16:56Z")

</div>

Brilliant. Thank you so much Simon!

---

<div class="post-metadata">

**Author:** ![dylanb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dylanb/32/139102_2.png) [@dylanb](https://meta.discourse.org/u/dylanb)\
**Post date:** [2019年五月26日 18:42 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/33 "2019-05-26T18:42:02Z")

</div>

> [@simon](#):
>
> Yes, importing your Discourse users to WordPress prior to enabling SSO would solve the email verification issue. I’d like to find a more straightforward way of dealing with the issue though.

Before I do this, is there any potential downside or risk as far as importing all of the users?

They will just have to create a new password to login again, right?

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2019年五月26日 18:52 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/34 "2019-05-26T18:52:42Z")

</div>

> [@dylanb](#):
>
> any potential downside or risk as far as importing all of the users?

The biggest risk I can think of would be if something goes wrong during the import process. It would be good to test it out the process with a throw-away gmail account before importing all of your users. That will also let you see what the password reset process will be like from the user’s point of view.

---

<div class="post-metadata">

**Author:** ![dylanb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dylanb/32/139102_2.png) [@dylanb](https://meta.discourse.org/u/dylanb)\
**Post date:** [2019年五月28日 19:10 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/35 "2019-05-28T19:10:43Z")

</div>

Once I import all Discourse users into WP and enable SSO with WP as the provider. I’ll want to check both of these boxes, correct?

 ![image](https://global.discourse-cdn.com/meta/original/3X/7/3/73dca68638e5751afe626be09b2bf6590c893689.png)

This will sync a user with the same email address and create users in Discourse that don’t already have a discourse account w/ that email address?

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2019年五月28日 19:18 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/36 "2019-05-28T19:18:39Z")

</div>

No, you do not need to enable either of those webhook settings. The SSO Provider code will take care of that for you.

You may want to enable the ‘Create or Sync Discourse Users on Login’ option that is found on the SSO Provider tab. When that setting is enabled, Discourse users will be automatically created when a user first logs into WordPress. Enabling this setting isn’t required to deal with the users you are importing into WordPress from Discourse.

---

<div class="post-metadata">

**Author:** ![dylanb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dylanb/32/139102_2.png) [@dylanb](https://meta.discourse.org/u/dylanb)\
**Post date:** [2019年五月28日 20:12 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/37 "2019-05-28T20:12:54Z")

</div>

Thanks. I was thinking more about current WordPress users that might not be in Discourse yet. Will they just get created on first login?

Or current WordPress users that might have an email match in Discourse but aren’t linked yet.

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2019年五月28日 20:18 UTC](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334/38 "2019-05-28T20:18:10Z")

</div>

Yes, existing WordPress users who do not yet have accounts on Discourse will have accounts created for them when the first login to Discourse with SSO.

If you would like Discourse users to be automatically created _before_ users login to your Discourse site, enable the ‘Create or Sync Discourse Users on Login’ option on the plugin’s SSO Provider tab. This will cause Discourse users to be created when they login to your WordPress site.

[上一頁](https://meta.discourse.org/t/merging-existing-discourse-and-wp-user-lists/115334.md?page=1)
