Register email as username

I am using WordPress 4.9.4 in a WordPress Multisite, and I need to allow users to register using their email address as username.
Looking at the code I found that what prevents me from accomplish that is that in the ms-functions.php there is a regular expression filtering usernames that have other characters than a-z, so when an email is the username I would get “Usernames can only contain lowercase letters (a-z) and numbers.”
I changed that regular expression in the ms-functions.php and it works fine. Now my question is, I don’t want to have to recode the function wpmu_validate_user_signup every time I update my wordpress. What would be good practices regarding this issue? Should I create another includes/ms-functions.php in a theme_child? If so, can I create only this function or I have to copy the entire ms-functions.php?

Thanks

4 Answers
4

Emails can not be used as user names as wordpress uses user names by default as part of urls (for example the author page). Therefor it is not enough to let users register with email addresses, you also need to have some code to handler the URL related issues.

Anyway this sounds like an XY problem. Since users can login with their email address why would any one actually care what is their login handle created at registration time? The most simple thing to do is to create a registration form in which you create a “sanitized” user name for the user based on his email if you do not want him to think of one.

Leave a Comment