ssss
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
1 changed file
with
7 additions
and
26 deletions
| ... | @@ -150,40 +150,21 @@ add_action( 'um_submit_form_errors_hook__registration', 'um_validate_email_domai | ... | @@ -150,40 +150,21 @@ add_action( 'um_submit_form_errors_hook__registration', 'um_validate_email_domai |
| 150 | 150 | ||
| 151 | 151 | ||
| 152 | function is_valid_email_domain($login, $email, $errors ){ | 152 | function is_valid_email_domain($login, $email, $errors ){ |
| 153 | $valid_email_domains = array("gotenzing.com","ekccu.com","stellervista.com");// allowed domains | 153 | $allowed_email_domains = array("gotenzing.com","ekccu.com","stellervista.com");// allowed domains |
| 154 | $valid = false; // sets default validation to false | 154 | $valid = false; // sets default validation to false |
| 155 | foreach( $valid_email_domains as $d ){ | 155 | if ( isset( $email ) && is_email( $email ) ) { |
| 156 | $d_length = strlen( $d ); | 156 | $email_domain = array_pop( explode( '@', trim( $email) ) ); |
| 157 | $current_email_domain = strtolower( substr( $email, -($d_length), $d_length)); | 157 | if ( in_array( $email_domain, $allowed_email_domains ) ) { |
| 158 | if( $current_email_domain == strtolower($d) ){ | 158 | $valid = true; |
| 159 | $valid = true; | 159 | } |
| 160 | break; | ||
| 161 | } | ||
| 162 | } | 160 | } |
| 163 | // Return error message for invalid domains | 161 | // Return error message for invalid domains |
| 164 | if( $valid === false ){ | 162 | if( $valid === false ){ |
| 165 | 163 | ||
| 166 | $errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: Registration is only allowed from selected approved domains. If you think you are seeing this in error, please contact the system administrator.' )); | 164 | $errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: Registration is only allowed from selected approved domains. If you think you are seeing this in error, please contact the system administrator.' )); |
| 167 | } | 165 | } |
| 168 | } | 166 | } |
| 169 | add_action('register_post', 'is_valid_email_domain',10,3 ); | 167 | add_action('register_post', 'is_valid_email_domain',10,3 ); |
| 170 | 168 | ||
| 171 | 169 | ||
| 172 | 170 | ||
| 173 | |||
| 174 | add_action( 'um_submit_form_errors_hook__registration', 'um_register_email_provider_restrict', 99 ); | ||
| 175 | |||
| 176 | function um_register_email_provider_restrict( $args ) { | ||
| 177 | // List the email providers you want to allow | ||
| 178 | $allowed_domains = array("gotenzing.com","ekccu.com","stellervista.com"); | ||
| 179 | |||
| 180 | // For each domain provider check if the domain provider is allowed for registration. | ||
| 181 | foreach( $allowed_domains as $domain ) { | ||
| 182 | if ( isset( $args['user_email'] ) ) { | ||
| 183 | if ( !strstr( $args['user_email'], $domain ) ) { | ||
| 184 | $message = sprintf( __( 'Only use the email domain %1$s, %2$s for registration', 'ultimate-member' ), $allowed_domains[0], $allowed_domains[1] ); | ||
| 185 | UM()->form()->add_error( 'user_email', $message ); | ||
| 186 | } | ||
| 187 | } | ||
| 188 | } | ||
| 189 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment