• Resolved intstr

    (@intstr)


    Hello,

    I am trying to make it so that only people from a certain email provider can register through UM. The code that I currently put in my functions.php is:

    function my_submit_form_errors_registration( $args ) {
    
    	// Change allowed email domains here
    	$allowed_email_domains = apply_filters( 'um_allowed_email_domains', array(
    			'yahoo.com'
    			) );
    
    	// Change error message here
    	$message = __( 'You can not use this email domain for registration', 'ultimate-member' );
    
    	if ( isset( $args['username'] ) && is_email( $args['username'] ) ) {
    		$email_domain = array_pop( explode( '@', trim( $args['username'] ) ) );
    		if ( !in_array( $email_domain, $allowed_email_domains ) ) {
    			UM()->form()->add_error( 'username', $message );
    		}
    	}
    }
    add_action( 'um_submit_form_errors_hook__registration', 'my_submit_form_errors_registration', 10, 1 );

    For some reason this code appears to do nothing because when trying to register with an email from for example gmail.com it still allows me to do so.

    I am looking forward to a response.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • missveronica

    (@missveronicatv)

    @intstr

    You can try this plugin “UM White Listing Email Domains and Email Addresses”

    https://github.com/MissVeronica/um-white-listing-email-domains

    Plugin Support yuriinalivaiko

    (@yuriinalivaiko)

    Hi @intstr

    There is a mistake in your code. You used the 'username' key in your code, but there is no field with this key in the registration form.

    You have to use the 'user_email' key that corresponds to the “E-mail Address” field. There is a code example for the custom email validation in the documentation: https://docs.ultimatemember.com/article/62-block-any-registration-that-does-not-use-gmail-as-mail-provider

    Regards

    Thread Starter intstr

    (@intstr)

    Thanks for the response @yuriinalivaiko

    I have tried replacing ‘username’ with ‘user_email’

    function my_submit_form_errors_registration( $args ) {
    
    	// Change allowed email domains here
    	$allowed_email_domains = apply_filters( 'um_allowed_email_domains', array(
    			'yahoo.com'
    			) );
    
    	// Change error message here
    	$message = __( 'You can not use this email domain for registration', 'ultimate-member' );
    
    	if ( isset( $args['user_email'] ) && is_email( $args['user_email'] ) ) {
    		$email_domain = array_pop( explode( '@', trim( $args['user_email'] ) ) );
    		if ( !in_array( $email_domain, $allowed_email_domains ) ) {
    			UM()->form()->add_error( 'user_email', $message );
    		}
    	}
    }
    add_action( 'um_submit_form_errors_hook__registration', 'my_submit_form_errors_registration', 10, 1 );

    I think I might be putting the code at the wrong location. It is currently located at public_html/wp-content/themes/riverbank/functions.php right before the bootstrap();.

    Is this the correct location?

    Plugin Support yuriinalivaiko

    (@yuriinalivaiko)

    You should add this PHP snippet to the end of the functions.php file in the active theme directory.

    Is public_html/wp-content/themes/riverbank/ your active theme?

    Regards

    Plugin Support andrewshu

    (@andrewshu)

    Hi @intstr

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘create a whitelist for emails at regestration’ is closed to new replies.