Recently I needed a way to add multiple users with a Contributor role on a WordPress website. The added user would not have WordPress login access and would only be used to identify which articles they contributed to the website. The problem was that to add a user in WordPress, you need to also provide a unique email address not yet used by another user as duplicate emails are not allowed in WordPress.
This article will show how to add multiple users using the identical Gmail address without adding any code or using a plugin.
If we try to add a new user in WordPress with an already existing email, we get the following error message:
It makes sense for WordPress to require a unique email per user since the email is used for login purposes and password recovery. But, what if for whatever reason, we want to add users that use the same email address anyway.
Let's first quickly check if there are any plugins available for this kind of task and how could this be achieved by adding code to the WordPress theme.
Looking at the plugins, I could only find one for this purpose Allow Multiple Accounts, but it is a very old plugin that hasn't been updated since 2015 and due to being so old has since stopped working.
So, currently, no recent plugin seems to be available to support multiple users with the same email, but how about achieving this task programmatically?
Using pre_user_email filter
When a user is created or updated, a pre_user_email filter is fired just before the WordPress checks if the email exists in the database. I can imagine this filter could be used to make an email unique when the user is created.
I haven't tried to use this approach myself, but you can get the idea of how this would work and see the code needed in this stackoverflow answer. The plugin mentioned earlier also uses a very similar technique.
Using this approach might only make sense if you want other users to register on your website. I needed a simpler solution since not many users would be added and I just needed a way to add them manually while avoiding creating a new email account for each user.
In the end, I used the alias feature of Gmail accounts to add multiple users who all use the same identical email.
So what is the alias feature in Gmail? Basically, the alias allows us to create separate email addresses that are still managed by the main Gmail email address. When an email is sent to the alias address, we receive it on the main email address.
Here is an example of five WordPress users, each having a unique email address thanks to the alias feature while in reality, they all point to one single email address.
We can create unlimited aliases in two ways. By using a
. dot character and a
+ plus sign on the existing Gmail account name.
Using the . dot character to make a Gmail alias
. dot character in the Gmail account name, the Gmail will ignore all the dots in the name and send the email to the account without dots.
So, let's assume we have the following existing Gmail that we have access to at [email protected].
We could then add users that would have the "unique" emails shown below while in reality, they would all still point to our original [email protected] email address.
A much more flexible way is to use the
+ plus sign.
Using The + plus sign to make a Gmail alias
+ plus sign, the Gmail will ignore the
+ character and also everything that follows after it. So, for example, we could use our working Gmail [email protected] and then add
+ sign followed by the name of the user to make the email for WordPress unique.
Again, all the emails above would still point to [email protected], but for WordPress, they would all be considered to be unique emails.
In this article, we learned how to add different users that use the same email address in WordPress. We checked for plugins that offer this task and there was one but has since been abandoned. There is also a WordPress filter available that might be used to achieve this by code, but the easiest way is to use the Gmail alias feature to trick the WordPress thinking that the users are all having unique email addresses.