Is there a way to restrict who can subscribe to a member level?
Example would be only allowing users with a .edu email address to subscribe to a certain level.
Is there a way to restrict who can subscribe to a member level?
Example would be only allowing users with a .edu email address to subscribe to a certain level.
I haven’t tried restricting the application of an email whitelist to a specific user level, so you’ll have to modify this code for your purposes. Subject to that caveat, this code works with any s2Member Pro form (including free Pro forms):
function kts_restrict_domains( $response, $form, $s ) {
$whitelist = array(
'someplace.edu',
'someotherplace.edu',
);
if ( !$response ) // No other errors produced by s2Member itself?
if ( $form === 'registration' || !is_user_logged_in() ) // Any new registration, or any new user completing checkout.
{
$domain = ''; // Initialize.
if( isset( $s['email']) && strpos( ( string)$s['email'], '@' ) !== FALSE )
list(, $domain) = explode('@', ( string )$s['email'], 2 );
if ( !$domain || !in_array( strtolower( $domain ), array_map( 'strtolower', $whitelist ), TRUE ) )
$response = array(
'error' => TRUE, // This is an error.
'response' => _x( 'ERROR: You must register using the email address associated with your institution.', 's2member-front', 's2member' ),
);
}
return $response; // Always return the filtered response.
}
add_filter( 'ws_plugin__s2member_pro_paypal_form_submission_validation_response', 'kts_restrict_domains', 10, 3 );
add_filter( 'ws_plugin__s2member_pro_stripe_form_submission_validation_response', 'kts_restrict_domains', 10, 3 );