[wp-trac] [WordPress Trac] #44347: WP allows creating username that is already used email address
WordPress Trac
noreply at wordpress.org
Sun Jun 10 23:15:17 UTC 2018
#44347: WP allows creating username that is already used email address
---------------------------+------------------------------
Reporter: phillipburger | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Users | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
---------------------------+------------------------------
Changes (by pbiron):
* component: General => Users
Comment:
Welcome to trac!!!
Nice catch...in all my years building WP sites I never thought to use
email addresses as usernames :-)
In the support topic you reference you say,
> I have since added a check in my code to stop this
I'm not sure how you implemented that check, but I would suggest you do so
using the
[[https://developer.wordpress.org/reference/hooks/username_exists/|username_exists]]
filter, as follows:
{{{#!php
<?php
add_filter( 'username_exists', 'my_username_exists_filter_func', 10, 2 );
function my_username_exists_filter_func( $user_id, $username ) {
if ( $user_id ) {
return $user_id;
}
return get_user_by( 'email', $username );
}
}}}
This will cause
[[https://developer.wordpress.org/reference/functions/wp_create_user/|wp_create_user()]]
to return a `WP_Error` and the new user will not be created.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44347#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list