4

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.

4

Unfortunately, this just isn't possible. There are three occasions where WordPress performs this check:

  1. When you click 'save' on the edit user screen( https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/user.php#L157 )
  2. When a user is registered ( https://github.com/WordPress/WordPress/blob/master/wp-includes/user.php#L2023 )
  3. When a user is created/inserted into the dtabase ( https://github.com/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...

  • Thanks. That's kind of where I expected to end up. I'll probably just use dummy email addresses. Our domain doesn't have any email accounts tied to it, so it won't be a problem to create those fake accounts. – mecnc May 12 '14 at 17:53
1

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!

0

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.org/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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.