• Resolved amityweb

    (@amityweb)


    We have a list of countries that the whole site is blocked in.

    The customer has asked can we allow certain pages to be viewed in SOME of the countries?

    Is this possible, bespoke code is fine for us.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Pascal

    (@iqpascal)

    Hi,

    No it is not possible to allow some pages / posts to not be blocked to a range of countries blocked. It is blocked for all countries or for none.

    Thread Starter amityweb

    (@amityweb)

    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.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can I unblock some pages to some countries, but not all blocked countries?’ is closed to new replies.