I have a very specific user registration process to implement on a website. I need to follow these steps when a user register via the front-end form :

  1. check email domain

    • if whitelisted domain: regular wordpress workflow (user registered, email notifications sent then user can choose is password during the first authentication process)
  2. If blacklisted domain

    • create user in DB
    • assign a custom WP role (eg. 'temp_account') for this user
    • don't send regular wordpress mail notifications
    • user with 'temp_account' role can't login

I can't find the proper action/filter I need to use for checking the email then prevent wordpress from sending default notifications...

Any advice/suggestion would be appreciated ;)

1 Answer 1


TO really fit your needs, I think it's better to rewrite some part of wp_insert_user() function, some part can interrest you

   $user_email = apply_filters( 'pre_user_email', $raw_user_email );

And :

   $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );

if ( in_array( strtolower( $user_login ), array_map( 'strtolower', $illegal_logins ) ) ) {
    return new WP_Error( 'invalid_username', __( 'Sorry, that username is not allowed.' ) );

And :

     if ( isset( $userdata['role'] ) ) {
         $user->set_role( $userdata['role'] );
     } elseif ( ! $update ) {

I think you'll be able to combine all these parts to make your own user registration.

Hope it helps !

  • Hi @Benoti ! I know I need to change/override this wp_insert_user() behavior but I'm not very comfortable with the idea of a "function rewriting"... I would rather use filters or actions. Nov 14, 2016 at 16:38
  • Unfortunatly as you can see, there is no filter or action at this step :-(
    – Benoti
    Nov 14, 2016 at 16:41
  • I think maybe I can use one(or both) user_registeror register_new_user actions but I can't find the right spot to check the email and force custom role before notifications are sent... Nov 14, 2016 at 16:50
  • I think thèse functions are just to register with default parameter. But you maybe can use the filter of $illegal_logins if you only allow user name/login as email ?
    – Benoti
    Nov 14, 2016 at 16:56

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.