Skip to content

Instantly share code, notes, and snippets.

@cryptexvinci
Last active November 21, 2020 03:32
Show Gist options
  • Save cryptexvinci/754425df8ea2df1b843ac2bad9e95cd0 to your computer and use it in GitHub Desktop.
Save cryptexvinci/754425df8ea2df1b843ac2bad9e95cd0 to your computer and use it in GitHub Desktop.
Ultimate Member - Only use a Selected email domain for registration
<?php
/**
* Ultimate member - Restrict registration based on email domain.
* URL: https://wordpress.org/support/topic/email-domain-restriction-at-registration/
*/
add_action( 'um_submit_form_errors_hook__registration', 'um_register_email_provider_restrict', 99 );
function um_register_email_provider_restrict( $args ) {
// List the email providers you want to allow
$allowed_domains = array('@gmail.com', '@hey.com');
// For each domain provider check if the domain provider is allowed for registration.
foreach( $allowed_domains as $domain ) {
if ( isset( $args['user_email'] ) ) {
if ( !strstr( $args['user_email'], $domain ) ) {
$message = sprintf( __( 'Only use the email domain %1$s, %2$s for registration', 'ultimate-member' ), $allowed_domains[0], $allowed_domains[1] );
UM()->form()->add_error( 'user_email', $message );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment