Ok, I have managed to do what i want with this custom code in functions.php which will add the IP address into the allow list if using a special URL variable. So this way they can just share the address https://mysite.com?allowAccess with anyone from any blocked country. It will also save a cookie so if their IP address changes, it will re-add their new one, so no need to re-visit the URL unless Ip changes AND cookies are deleted.
function mysite_allow_access()
{
if( isset($_GET['allowAccess']) && $_GET['allowAccess'] == true && !isset($_COOKIE['allowAccess']) )
{
setcookie('allowAccess', 'true', time() + (10 * 365 * 24 * 60 * 60));
}
if( (isset($_GET['allowAccess']) && $_GET['allowAccess'] == true) || isset($_COOKIE['allowAccess']) )
{
$allowed_ip = $_SERVER['REMOTE_ADDR'];
$blockcountry_frontendwhitelist = get_option( 'blockcountry_frontendwhitelist' );
$blockcountry_frontendwhitelistArray = explode(';',$blockcountry_frontendwhitelist);
if(!in_array($allowed_ip, $blockcountry_frontendwhitelistArray))
{
$blockcountry_frontendwhitelistArray = array_filter($blockcountry_frontendwhitelistArray);
$blockcountry_frontendwhitelistArray[] = $_SERVER['REMOTE_ADDR'];
$blockcountry_frontendwhitelist = implode(';',$blockcountry_frontendwhitelistArray);
update_option('blockcountry_frontendwhitelist', $blockcountry_frontendwhitelist.';');
wp_redirect('https://mysite.com');
exit;
}
if( (isset($_GET['allowAccess']) && $_GET['allowAccess'] == true) )
{
wp_redirect('https://mysite.com');
exit;
}
}
}
add_action('init', 'mysite_allow_access');
-
This reply was modified 3 years, 11 months ago by
amityweb.