0

I have previously added the following code in /wp-includes/user but it restricts registration to only front-end user. I want to put restriction on back-end user addition.

elseif (!preg_match('#[@.]gmail.com$#i', $user_email){
    $errors->add( 'invalid_email', __( 'ERROR: Only "gmail.com" email address allowed.' ) );
    $user_email = '';
}
  • Did you modify the core files? If yes, that's not a good idea. Please reverse this and update your question about what exactly you are looking for, so we can offer a solution. – Jack Johansson Apr 18 '17 at 8:05
  • yes i have reverted them. My question is how to restrict Admin so that he can create only one domain backend users from Add new user screen in dashboard. – Rhae Apr 18 '17 at 9:10
0

You can hook into registration_error and check if the user's email is under your specified domain or not:

add_filter( 'registration_errors', 'user_email_checker', 10, 3 );
function user_email_checker( $errors, $sanitized_user_login, $user_email ) {
    if ( !preg_match('#[@.]gmail.com$#i', $user_email ) {
        $errors->add( 'invalid_email', __( 'ERROR: Only "gmail.com" email address allowed.' ) );
    }
    return $errors;
}

This way you don't have to deal with the core directly.

Further readings at : WordPress Codex.

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.