I'm creating a site using WordPress and BuddyPress. Registrations should be open to everyone with a .edu email address.
If I was using vanilla WordPress, doing this would be pretty straightforward using the registration_errors
filter, but that doesn't work when BuddyPress is installed. The filter doesn't seem to ever be called. If I deactivate BuddyPress, it works fine.
From what I've read, although BuddyPress does have custom validation hooks for extra profile fields beyond the WordPress defaults, you're supposed to use standard WordPress hooks for things like usernames and email addresses.
Has anyone run into this issue? Is there another filter or hook that I should be using?
The correct hook is bp_signup_validate
. The hooked function isn't passed any parameters, but I can access the global $bp object and modify it to add custom email validation and error messages:
function validate_email_edu(){
global $bp;
$email = $bp->signup->email;
if ($email){
$tld_index = strrpos($email,'.');
$tld = substr($email,$tld_index);
if ($tld != '.edu'){
$bp->signup->errors['signup_email'] = 'Sorry, you must have a .edu email address to register.';
}
}
}
add_action('bp_signup_validate','validate_email_edu');