• Resolved mungbean

    (@mungbean)


    In order to allow only .edu emails for registration, do I need to exclude or blacklist every top level domain name, including regional? Or is there an easier way?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Benaceur

    (@benaceur)

    you want to prevent all emails that end with .edu?

    Thread Starter mungbean

    (@mungbean)

    Hi there,

    No, the opposite. I only want to allow registration from emails that end in .edu domain. Student registration only.

    Thanks again

    Plugin Author Benaceur

    (@benaceur)

    use this code temporarily, put it in the file (functions.php) of your active theme.
    in the next version of the plugin I will add this option, so do not forget to remove the code to the next version.
    the code:

        global $ben_____restricted_domain_emails;
        $ben_____restricted_domain_emails = false;
    		
        add_filter( 'user_registration_email', function( $email ) {
    		global $ben_____restricted_domain_emails;
    		
    		$BlackList = array('edu');
    		$scts = explode('.', $email);
    		$domains = $scts[count($scts)-1];
    		
    		if ( !in_array( $domains, $BlackList ) && $email != '' && !email_exists( $email ) ) {
    		$ben_____restricted_domain_emails = true;
    		}
    		
    		return $email;		
    	});
    
        add_filter( 'registration_errors', function( $errors, $login ) {
    		global $ben_____restricted_domain_emails;
    		
    		if ( $ben_____restricted_domain_emails )
    			$errors->add( 'invalid_email', __( '<strong>ERROR</strong>: Sorry, this email address is not allowed.' ) );
    			
    		return $errors;
    	}, 9, 2 );

    you can add other domain, example:
    $BlackList = array('edu','com','net');

    The direct support of this plugin:
    https://benaceur-php.com/?p=2268

    • This reply was modified 5 years, 4 months ago by Benaceur.
    • This reply was modified 5 years, 4 months ago by Benaceur.
    Thread Starter mungbean

    (@mungbean)

    Wonderful! Thanks for your help and consideration.

    What is your ETA for the next release for this plugin?

    Plugin Author Benaceur

    (@benaceur)

    to the next version (I do not know when)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Only allow .edu email registrations’ is closed to new replies.