Allow Duplicate Email Address for Different Users

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.

3 s
3

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…

Leave a Comment