Created
June 16, 2020 08:05
-
-
Save robertuniqid/143ab0544ac1bb631d5e192d1d492ad9 to your computer and use it in GitHub Desktop.
Hackish - Prevent username with spaces in it - WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'pre_user_login', function( $user_login ) { | |
if( strpos( trim( $user_login ), ' ' ) !== false ) { | |
add_filter( 'gettext', function( $translation, $text ) { | |
if( $text === 'Cannot create a user with an empty login name.' ) | |
return __( "You're not allowed to have spaces in your username" ); | |
return $translation; | |
}, 20, 2 ); | |
return ''; | |
} | |
return $user_login; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment