Reply To: Restrict registration to email whitelist

Home Forums User Registration Restrict registration to email whitelist Reply To: Restrict registration to email whitelist

#6461

sanjeev3
Member

Hello Nikolay,

Please use provided user registration hook user_registration_validate_user_email instead. Paste the following codes to your child theme’s functions.php

add_action( 'user_registration_validate_user_email','ur_validate_user_email', 10, 4 );

function ur_validate_user_email( $single_form_field, $data, $filter_hook, $form_id ) {

	$value 	   = isset( $data->value ) ? $data->value : '';
	$whitelist = array( 'sizeableinteractive.com', 'theandystratton.com' );
	$parts     = explode( '@', $value );

	if( ! in_array( $parts[1], $whitelist ) ) {

	    add_filter( $filter_hook, function ( $msg ) use ( $field_label ) {
	        return __( 'You may only register with an approved email address.', 'user-registration' );
	   });
	}
}

Let me know if you have any further confusion.

Regards,
WPEverest Support