0

I'am working on a new wordpress website, and I would like to create multiple users with the same exact email address. The purpose of this is to route several customer service accounts to a common email as means of consolidation.

I started by registering an email field in the rest api, as email field is not included in the default rest api settings.

Hence the following code was added in my functions.php file:

register_rest_field( 'user', 'user_email',
                        array(
                            'get_callback'    => function ( $user ) {
                                return get_userdata($user['id'])->user_email;
                            },
                            'schema'          => null,
                        )
                    );
                

Then I issue 2 simple post requests using python to create 2 accounts with the same email,as follows:

import base64
import requests
import json

url='https://mywebsite.com/wp-json/wp/v2/users'

from Load_Credentials import user,password

credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header = {'Authorization': 'Basic ' + token.decode('utf-8'),'Content-Type': 'application/json','User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}


#first POST request with same email
x1={"username": "newuser1","email":"[email protected]","password":"check123"}
x1=json.dumps(x1)
x1=json.loads(x1)
r1=requests.post(url+'?status=publish',headers=header,json=x1)

#second post request with same email
x2={"username": "newuser2","email":"[email protected]","password":"check123"}
x2=json.dumps(x2)
x2=json.loads(x2)
r2=requests.post(url+'?status=publish',headers=header,json=x2)

This is the response I'am getting:

{'code': 'existing_user_email', 'message': 'Sorry, that email address is already used!', 'data': None}

Is there a way to allow creating 2 accounts with the same email ONLY when using the rest api. (normal registration procedure should continue to flag duplicate emails)

I appreciate your support on this matter.

1 Answer 1

0

I don't think it's possible. Using rest API or not do not change the fact WordPress is preventing it AT https://github.com/WordPress/wordpress-develop/blob/5.9/src/wp-includes/user.php#L2032

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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