5

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
    if(!$user){
        $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;
        }else{
            return $user; //passed
        }
    }
}, 20, 3);

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

http://example.com/author/email-address/

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?

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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