I found this code in another forum, but when I tried to add it to functions.php file it still allowed registration from .com emails:
add_action(‘registration_errors’, ‘validate_email_domain’, 10, 3);
function validate_email_domain( $errors, $login, $email ) {
$expression = “/.*@(.*.edu)/”;
if ( is_email($email) ) {
if ( !preg_match($expression,$email) ) {
$errors->add(’email_domain’, __(‘ERROR: You may only register with a .edu email address.’));
}
}
return $errors;
}
Try this:
add_action('registration_errors', 'validate_email_domain', 10, 3);
function validate_email_domain( $errors, $login, $email ) {
if ( is_email($email) and substr($email, -3) != 'edu' ) {
$errors->add('email_domain', __('ERROR: You may only register with a .edu email address.'));
}
return $errors;
}
Thank you!
I pasted that code into the bottom of my functions.php page (above the last ?>), but when I pressed save it went to a HTTP 500 Internal Server Error page. Then the whole site stopped loading until I removed that snippet of code. Any ideas?
Just tried this myself, and I didn’t get an error. Are you sure you didn’t add it into another function in that file?
In other words, does the last ?> actually indicate the end of the page, or just the end of the last function? (It isn’t necessary to have a ?> to end the file. )
So maybe try it again, but pasting what krumch has given you after the last ?>?
I tried adding it after the last ?> and it is now showing at the top of the page: http://www.softwarephd.com/
Sorry, I’m not very familiar with custom coding. Thanks for your suggestions!
Then it doesn’t go there!
Are you or your host running any caching?
Not anything I’ve setup that I know of. I use bluehost which is a pretty standard hosting service.
Well, I don’t know what caused the response to krumch’s code.
But I realize we should have asked whether you are you using a WordPress registration form or an s2Member registration form. Neither code you’ve been given will work with s2Member’s registration form.
Yes, I’m using an s2Member reg form.
Yes, I’m using an s2Member reg form.
@marktvb: This code should be in mu-plugins/s2-hacks.php file. To use it with s2M registration forms, you must find a good hook to run the function with. I search in s2M codes – always works for me.
Okay, can you explain that a little more. I’m not sure what exactly to do. What do you mean by a hook?
Perhaps you could try this in mu-plugins/s2-hacks.php:
add_action('ws_plugin__s2member_after_register', 'validate_email_domain', 10, 3);
function validate_email_domain( $errors, $login, $email ) {
if ( is_email($email) and substr($email, -3) != 'edu' ) {
$errors->add('email_domain', __('ERROR: You may only register with a .edu email address.'));
}
return $errors;
}
Let us know if it works!
Sorry marktvb, somehow I missed your question.
Thanks KTS915 for answering š
I really appreciate your help. When I added that code to the s2-hacks.php file the code just showed up at the top of the site. http://www.softwarephd.com
Did I do something wrong?