Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Created December 21, 2015 18:43
Show Gist options
  • Save cartpauj/2c37fd3fbbec9509b916 to your computer and use it in GitHub Desktop.
Save cartpauj/2c37fd3fbbec9509b916 to your computer and use it in GitHub Desktop.
Limit signups on a particular Membership by email domain
<?php
function ends_with($haystack, $needle = '.ac.uk') {
return (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
}
function check_email_domain($errors) {
$membership_id = 123; //Change this to reflect your Membership ID
if($membership_id != $_POST['mepr_product_id']) {
return $errors;
}
$email = stripslashes($_POST['user_email']);
if(!ends_with($email)) {
$errors[] = "Sorry, only valid .ac.uk email addresses are allowed on this Membership";
}
return $errors;
}
add_filter('mepr-validate-signup', 'check_email_domain');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment