Allow registration for certain email domain on WordPress

Welcome mkmcst community Forum Web programming WordPress Random wordpress Allow registration for certain email domain on WordPress

Viewing 0 reply threads
  • Author
    Posts
    • #8853
      Michael Mc
      Keymaster
      @mkmcst
      function is_valid_email_domain($login, $email, $errors ){
       $valid_email_domains = array("gmail.com","yahoo.com");// whitelist email domain lists
       $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 message
       if( $valid === false ){
       $errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: you can only register using @gmail.com or @yahoo.com emails' ));
       }
      }
      add_action('register_post', 'is_valid_email_domain',10,3 );
      

      Now look at the second line of the above code:

      $valid_email_domains = array(“gmail.com”,”yahoo.com”);// whitelist email domain lists
      You will see where to list the email domain for whitelist those email which you want users to be able to register on your WordPress site. You can list more email and those email domain which you want to be allowed for user registration on your WP site. Just place those email domain in the same manner by comma separated and inside the quotation.

Viewing 0 reply threads
  • You must be logged in to reply to this topic.