Created
September 29, 2018 16:52
-
-
Save tokkonopapa/b624f7fde98aaaedc6b6061b9eff0711 to your computer and use it in GitHub Desktop.
Block specific countries on public facing pages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Drop-in for IP Geo Block custom filters | |
* | |
* This file should be renamed to `drop-in.php`. | |
* | |
* @package IP_Geo_Block | |
* @author tokkonopapa <[email protected]> | |
* @license GPL-3.0 | |
* @link https://www.ipgeoblock.com/ | |
* @see https://www.ipgeoblock.com/codex/#filter-hooks | |
* @example Use `IP_Geo_Block::add_filter()` instead of `add_filter()` | |
*/ | |
class_exists( 'IP_Geo_Block', FALSE ) or die; | |
function my_blacklist( $validate ) { | |
// Countries blocked by all pages. | |
$blacklist = array( | |
'KR', | |
); | |
// Check if it is not blocked. | |
if ( empty( $validate['result'] ) ) { | |
// Check if it is in the black list. | |
if ( in_array( $validate['code'], $blacklist, true ) ) { | |
$validate['result'] = 'blocked'; | |
} | |
} | |
return $validate; | |
} | |
IP_Geo_Block::add_filter( 'ip-geo-block-public', 'my_blacklist' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://wordpress.org/support/topic/blocking-a-single-country/
Put this
drop-in.php
into the directory of geolocation API library, typically/wp-content/ip-geo-api/
.