/pmpro-restrict-countries.php
Forked from greathmaster/pmpro-restrict-countries.php
Created May 10, 2016
Restrict certain countries from signing up for certain levels.
function my_init() | |
{ | |
global $restricted_countries; | |
//specify the countries not allowed to signup. The key is the level id. | |
$restricted_countries = array( | |
1 => array('FR', 'IT'), | |
2 => array('IT'), | |
); | |
} | |
add_action('init', 'my_init'); | |
function my_pmpro_registration_checks($value) | |
{ | |
global $restricted_countries, $pmpro_msg, $pmpro_msgt; | |
$country = $_REQUEST['bcountry']; | |
$level_id = $_REQUEST['level']; | |
//only check if the level has restrictions | |
if(array_key_exists($level_id, $restricted_countries) && in_array($country, $restricted_countries[$level_id])) | |
{ | |
$pmpro_msg = "Your country of residence is not permitted to register for this level."; | |
$pmpro_msgt = "pmpro_error"; | |
$value = false; | |
} | |
return $value; | |
} | |
add_filter("pmpro_registration_checks", "my_pmpro_registration_checks"); | |
function my_pmpro_level_expiration_text($text, $level) | |
{ | |
global $restricted_countries, $pmpro_countries; | |
if(array_key_exists($level->id, $restricted_countries )) | |
{ | |
$text = $text." This level cannont be purchased if you reside in the following countries: "; | |
//code for commas | |
$i = 1; | |
foreach($restricted_countries[$level->id] as $country) | |
{ | |
$text = $text. $pmpro_countries[$country]; | |
if($i != count($restricted_countries[$level->id])) | |
$text = $text. ", "; | |
$i++; | |
} | |
} | |
return $text; | |
} | |
add_filter("pmpro_level_expiration_text", "my_pmpro_level_expiration_text", 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment