Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to let the user login either using username or email.

The only way to find the email is by detecting @ symbol using strpos.

However WordPress allow @ symbol in username too.

Can someone help me to invalidate username if it contains @ symbol in it..

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

In a multi-site installation it is 'wpmu_validate_user_signup':

add_filter( 'wpmu_validate_user_signup', 'wpse_77904_mu_no_at_in_username' );

function wpse_77904_mu_no_at_in_username( $user )
{
    if ( FALSE !== strpos( $user['user_name'], '@' ) )
        $user['errors']->add('user_name',  __( 'That username is not allowed.' ) );

    return $user;
}

On single-site it is 'validate_username':

add_filter( 'validate_username', 'wpse_77904_no_at_in_username', 10, 2 );

function wpse_77904_no_at_in_username( $valid, $username )
{
    if ( FALSE !== strpos( $username, '@' ) )
        return FALSE;

    return $valid;
}

Caveat: both not tested. :)

share|improve this answer
    
Great.. It works :) –  Giri Jan 1 '13 at 19:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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