Skip to content

Instantly share code, notes, and snippets.

@robertuniqid
Created June 16, 2020 08:05
Show Gist options
  • Save robertuniqid/143ab0544ac1bb631d5e192d1d492ad9 to your computer and use it in GitHub Desktop.
Save robertuniqid/143ab0544ac1bb631d5e192d1d492ad9 to your computer and use it in GitHub Desktop.
Hackish - Prevent username with spaces in it - WordPress
<?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