0

Hii i want to that whenever any user register at my wordpress that just accepet email of specific host for example if I want to accept only User register with username@gmail.com this email format otherwise that show some error that you can only register with @gmail.com so how to apply this condition and in which file thanks

2

I think the User Domain Whitelist plugin is exactly what you want:

The User Domain Whitelist/Blacklist plugin limits user registration to only registrants with an email address from the domain white list below OR prevents registrants with an email address from the domain black list below from registering.

0

Actually, this is a validation question, not really a WordPress question. You can add a JavaScript file that checks the value of the email field against @gmail.com on submission and either permits the form to submit or alerts the user to an error.

For example, this script would do what you want ...

jQuery(document).ready(function($) {
    $('#registerform').find(':submit').click(function(e) {
        if( ! isGmail( $('#user_email').val() ) ) {
            e.preventDefault(); // Prevent the form from submitting
            alert('You can only register with an @gmail.com email address!');
            return false;
        }
    });
});

function isGmail( address ) {
    return address.indexOf("@gmail.com", this.length - 10) !== -1;
}
0

You can use the register_post hook to check if the email domain is in your whitelist and if not just add an error which will tell the user to use an email from your whitelist, something like:

function is_valid_email_domain($login, $email, $errors ){
    $valid_email_domains = array("gmail.com","yahoo.com");// whitelist
    $valid = false;
    foreach( $valid_email_domains as $d ){
        $d_length = strlen( $d );
        $current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
        if( $current_email_domain == strtolower($d) ){
            $valid = true;
            break;
        }
    }
    // if invalid, return error
    if( $valid === false ){
        $errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: you can only register using gmail or yahoo emails' ));
    }
}

add_action('register_post', 'is_valid_email_domain',10,3 );

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.