[wp-trac] [WordPress Trac] #41672: REST create user: existing_user_login is returned before existing_user_email

WordPress Trac noreply at wordpress.org
Sat Aug 19 19:53:20 UTC 2017


#41672: REST create user: existing_user_login is returned before
existing_user_email
-------------------------------------------------+-------------------------
 Reporter:  bbrian                               |       Owner:
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Users                                |  Review
 Severity:  normal                               |     Version:  4.7
 Keywords:  needs-patch needs-unit-tests good-   |  Resolution:
  first-bug 2nd-opinion                          |     Focuses:  rest-api
-------------------------------------------------+-------------------------
Changes (by sconzof):

 * keywords:  needs-patch needs-unit-tests good-first-bug => needs-patch
     needs-unit-tests good-first-bug 2nd-opinion


Comment:

 The rest api `create_item` function for users (in class-wp-rest-users-
 controller.php) relies upon the core `wp_insert_user` function (in wp-
 includes/user.php). Logic for determining whether usernames and email
 addresses exist is implemented in the `wp_insert_user` function, and
 should probably stay there, and not be moved into class-wp-rest-users-
 controller.php.

 `wp_insert_user()` first checks to see if the username already exists with
 the `username_exists()` function. It immediately short-circuits with the
 error `existing_user_login`, and doesn't also check if the email also
 exists.

 ''Suggestion:'' Instead of immediately returning  `WP_Error(
 'existing_user_login', __( 'Sorry, that username already exists!' ) );`
 in the case of an existing username, the code ''could first call''
 `email_exists()`, then provide a different error message
 `existing_user_email` if ''BOTH'' the username and the email address
 already exist.

 However, the implication here is this will affect more than just the rest-
 api. This will have effects upon any code that uses the `wp_insert_user()`
 function.

 So, do we want to actually make this change or not?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41672#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list