I've changed the default registering option by allowing people to sign up with their e-mail addresses. They also have an option to add their firstname, lastname but it's not required.

// Allow email instead of nickname for login 
add_filter('authenticate', function($user, $email, $password){

    //Check for empty fields
    if(empty($email) || empty ($password)){        
        //create new error object and add errors to it.
        $error = new WP_Error();
        if(empty($email)){ //No email
            $error->add('empty_username', __('<strong>Viga</strong>: Unustasid sisestada e-posti aadressi'));
        else if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ //Invalid Email
            $error->add('invalid_username', __('<strong>Viga</strong>: E-posti aadress on vale.'));
        if(empty($password)){ //No password
            $error->add('empty_password', __('<strong>Viga</strong>: Unustasid sisestada parooli'));
        return $error;

    //Check if user exists in WordPress database
    $user = get_user_by('email', $email);

    //bad email
        $error = new WP_Error();
        $error->add('invalid', __('<strong>Viga</strong>: E-posti aadress või parool ei ole õige.'));
        return $error;
    else{ //check password
        if(!wp_check_password($password, $user->user_pass, $user->ID)){ //bad password
            $error = new WP_Error();
            $error->add('invalid', __('<strong>Viga</strong>: E-posti aadress või parool ei ole õige.'));
            return $error;
            return $user; //passed
}, 20, 3);

But this raises a problem. On the author page, users e-mail addresses become public:


I know how do change the /author/ part of the URL:

add_action('init', 'cng_author_base');
function cng_author_base() {
    global $wp_rewrite;
    $author_slug = 'autor'; // change slug name
    $wp_rewrite->author_base = $author_slug;

but not how do change the username to show the ID of the author. Can it be done?


2 Answers 2


Surprised to see this unanswered for this long. This is pretty simple to do with a simple block of code:

function set_my_nice_name() {
    global $wpdb;
    $user_table = $wpdb->prefix . 'users';
    $wpdb->query("UPDATE $user_table SET `user_nicename`=`ID`");
add_action('init', 'set_my_nice_name');

This works because the visible portion of an author slug (or profile slug in BuddyPress) uses the user_nicename column in the users table and this just copies the user ID to that column for everyone in the DB.


Something to have in mind is that authors queries could become really predictable. Adding +1 isn't that hard. Abuse from bots could arise, retrieving data through puppeteer for example.

We could append to the user ID the user_registered by sanitizing it. We would get a nice random-ish string of numbers which would actively prevent bots and users from jumping through pages.

We can catch the user ID upon registration then update user_nicename with the required value.

add_action( 'user_register', 'wpso208792' );

function wpso208792( $user_id ) {

    $userdata = array (
        'ID' => $user_id, 
        'user_nicename' => sanitize_title_with_dashes( $user_id . str_replace ( array( '-', ' ', ':', ), '', get_userdata( $user_id )->user_registered ) ),

    wp_update_user( $userdata );


If you're not interested in randomizing the user user_nicename just remove . str_replace ( array( '-', ' ', ':', ), '', get_userdata( $user_id )->user_registered ) from the value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.