admin管理员组文章数量:1391987
I need to be able to have different users share the same email address. (Running a site where parents will be creating accounts for their children who may not have their own email address, so the parent will need to use his or hers for each of the children's accounts.)
I have seen other suggestions, some include edited core (which I don't want to do), but nothing seems to work.
Does anyone have any ideas on how to bypass the email_exists check on user creation?
Thanks in advance.
P.S. Since I don't have the rep, I can't comment on the other post to ask if the OP found a solution.
I need to be able to have different users share the same email address. (Running a site where parents will be creating accounts for their children who may not have their own email address, so the parent will need to use his or hers for each of the children's accounts.)
I have seen other suggestions, some include edited core (which I don't want to do), but nothing seems to work.
Does anyone have any ideas on how to bypass the email_exists check on user creation?
Thanks in advance.
P.S. Since I don't have the rep, I can't comment on the other post to ask if the OP found a solution.
Share Improve this question asked May 12, 2014 at 17:20 mecncmecnc 531 gold badge1 silver badge3 bronze badges 2- I'm facing this same issue. Did anyone come up with anything following John Pederson's suggestion above? – Michael Walker Commented Feb 7, 2020 at 11:33
- I'd probably start with the plugin he linked to, which seems to do some or all of that already. – Rup Commented Feb 7, 2020 at 11:50
3 Answers
Reset to default 5Unfortunately, this just isn't possible. There are three occasions where WordPress performs this check:
- When you click 'save' on the edit user screen( https://github/WordPress/WordPress/blob/master/wp-admin/includes/user.php#L157 )
- When a user is registered ( https://github/WordPress/WordPress/blob/master/wp-includes/user.php#L2023 )
- When a user is created/inserted into the dtabase ( https://github/WordPress/WordPress/blob/master/wp-includes/user.php#L1610 )
Both (1) and (2) have hooks after them which allow you to remove any error message (added to an WP_Error()
object), and so effectively by-passing the check.
Unfortunately both (1) and (2) call (indirectly) wp_insert_user()
, and so (3). (There's a bit of maze of wp_insert_user()
, wp_update_user()
and wp_create_user()
:))
(3) is the stumbling block. Simply put you can't get round it.
But even if you could, it's probably best not to. Since a unique e-mail is widely expected, you maybe be using plug-ins that rely on that fact. WordPress itself relies on this fact when you use the 'forgotten password' feature.
This leaves you with two options:
- Create a 'fake' e-mail for child-accounts (but you'd need to be sure that the e-mail is fake given e-mail is fake - maybe use your domain?). Additionally you'd want to make absolutely sure that e-mails associated with such accounts are never used.
- Abandon the "user" approach and using something like a CPT. But this would rewriting a hell of a lot of code, some of it relating to user security (i.e. logging in, password storage etc). It isn't really a sane choice.
Unfortunately WordPress isn't designed for user relationship management...
I have found that it is actually possible to add a user with a new username but existing email address if you first call the following code:
define('WP_IMPORTING',true);
This constant is checked in wp-includes/user.php in the codex.
I assume this gets defined when WordPress runs one of its own data imports, to get around the errors caused by duplicate email addresses.
Hope that helps!
I've been looking into this issue as well, and attempting to come up with the best solution for a client request.
There are a couple of ways to achieve this, such as the dummy/fake emails, and create a secondary email field. Which will not trigger WP's unique email requirement. The new field can simply be labeled 'email2'.
'email2' can contain any information you want [limited by MySQL field definition]. Once it's created, add the same email across both accounts (or many multiple in my case).
Then in your code, make sure both accounts are mirrored for actions/triggers/updates etc...
For example, if account 1 has an automated message, and/or an account update etc... Your code could reference 'update all accounts where email2 = email2 of the current logged in WP_user'.
It's a work around, but should satisfy most client requests. They won't see what's going on in the backend. But when they login, they should see a 'combined' or 'mirrored' view of both accounts. Because, in essence, they are the same other than WPs unique email, and username requirements.
You can even do this with passwords. You cannot 'mirror' the passwords. However, you can reference and update/set the password, of all accounts where email2 = email2 of current logged in user [wp_set_password].
Also, there is this WP plugin [not my plugin FYI]:
https://wordpress/plugins/allow-multiple-accounts/
If anyone else has any other solutions, let's brainstorm and figure out the best solutions. Are there any better solutions? #StackExchangeIsCool
本文标签: Allow Duplicate Email Address for Different Users
版权声明:本文标题:Allow Duplicate Email Address for Different Users 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744769725a2624265.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论