I’ve just managed to get back to this today as the client delayed the project… lucky me. So I was able to spend some time today to work it out properly. I don’t have the special template nor the code hack. I’ve hidden the description div in my css (and the username div because I’m auto-generating that).
I’ve done everything in mu-plugins/s2-hacks.php.
Firstly, at init, I grab the desc attribute (I figured out how to get this). I validate the email address against my list and if it’s invalid save an extra response. Then I set the email to an empty string to force an error. Then with the ws_plugin__s2member_pro_before_sc_paypal_form hook, I output the jquery validation and my extra response. That means I get two error responses but I can live with that because technically it is an invalid email address and my response adds some extra information.
add_action('ws_plugin__s2member_pro_before_sc_paypal_form','extra_validation',10);
function extra_validation ($vars = array()) {
$js = "
<script>
jQuery(document).ready(function($) {
$('#s2member-pro-paypal-registration-form').find(':submit').click(function(e) {
mylist = '" . $vars['attr']['desc'] . "';
if( ! inList( $('#s2member-pro-paypal-registration-email').val(), mylist) ) {
e.preventDefault(); // Prevent the form from submitting
alert('You cannot register with an email address in the domain you specified. Please try again with a valid email or contact us if you wish to register.');
return false;
}
});
});
function inList(address, domains) {
var whitelist = domains.split('|');
var pieces = address.split('@');
var i = whitelist.length;
while (i--) {
if (whitelist[i] === pieces[1]) return true;
}
return false;
}
</script>
";
echo $js;
if(isset($GLOBALS['response_extra'])) {
echo $GLOBALS['response_extra'];
}
}
add_action('init','extra_stuff',1);
function extra_stuff() {
if (strpos($_SERVER["REQUEST_URI"], "/register-1") !== false) {
if(!isset($_POST["s2member_pro_paypal_registration"])) {
$_POST["s2member_pro_paypal_registration"]["username"] = generate_username();
} else {
$post_vars = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_POST["s2member_pro_paypal_registration"]));
$post_vars["attr"] = unserialize (c_ws_plugin__s2member_utils_encryption::decrypt ($post_vars["attr"])); /* And run a Filter. */
$post_vars["attr"] = apply_filters ("ws_plugin__s2member_pro_paypal_registration_post_attr", $post_vars["attr"], get_defined_vars ());
if (!is_valid_email_domain($post_vars['email'], $post_vars['attr']['desc'])) {
$_POST["s2member_pro_paypal_registration"]["email"] = '';
GLOBAL $response_extra;
$response_extra = '
<div id="s2member-pro-paypal-registration-form-response-section" class="s2member-pro-paypal-form-section s2member-pro-paypal-registration-form-section s2member-pro-paypal-form-response-section s2member-pro-paypal-registration-form-response-section">
<div id="s2member-pro-paypal-registration-form-response-div" class="s2member-pro-paypal-form-div s2member-pro-paypal-registration-form-div s2member-pro-paypal-form-response-div s2member-pro-paypal-registration-form-response-div">
<div id="s2member-pro-paypal-form-response" class="s2member-pro-paypal-form-response-error s2member-pro-paypal-registration-form-response-error">You cannot register with an email address in the domain you specified. Please try again with a valid email or contact us if you wish to register.</div>
</div>
<div style="clear:both;"></div>
</div>
';
}
}
}
}
So anyway what I’ve done is probably not the “correct” way but it works!