Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Alessandro Tesoro

    (@alessandrotesoro)

    Hi @wladino

    Yes that’s possible through filters, you’ll need to add your own custom validation rules.

    Here’s a quick example, you can copy and paste this code into your theme’s functions.php file.

    function wpum_my_own_validation( $pass, $fields, $values, $form ) {
    
    	if ( $form === 'registration' ) {
    
    		$email = isset( $values['register']['user_email'] ) ? $values['register']['user_email'] : false;
    
    		if ( $email ) {
    			$domain = substr( $email, strpos( $email, '@' ) + 1 );
    
    			$allowed_domains = [
    				'icloud.com',
    			];
    
    			if ( ! in_array( $domain, $allowed_domains, true ) ) {
    				return new WP_Error( 'email-validation-error', 'Your error message goes here.' );
    			}
    		}
    	}
    
    	return $pass;
    
    }
    add_filter( 'submit_wpum_form_validate_fields', 'wpum_my_own_validation', 20, 4 );

    Remember to modify the $allowed_domains variable with the list of domains you wish to allow.

    Thread Starter wladino

    (@wladino)

    Thank you for quick response, it does seem to work for me. I have tried it tweaking a bit the function but the registration process it is still going through. I will probably tackle it using JavaScript. Thanks again!

    Plugin Contributor Alessandro Tesoro

    (@alessandrotesoro)

    Hi @wladino

    The registration form shouldn’t be allowing you to bypass the signup with those rules. I’ve tested the code on my end before publishing it here.

    Have you made sure you’re registering from the WPUM registration form? Those rules will apply only to that form and not anywhere else.

    If you’re signing up from the wpum form, and it’s still allowing you to signup, would you mind emailing me to [email protected] so I can have a better look at it?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Restrict user email registration (Whitelist only)’ is closed to new replies.