Skip to content

Instantly share code, notes, and snippets.

@tokkonopapa
Created September 29, 2018 16:52
Show Gist options
  • Save tokkonopapa/b624f7fde98aaaedc6b6061b9eff0711 to your computer and use it in GitHub Desktop.
Save tokkonopapa/b624f7fde98aaaedc6b6061b9eff0711 to your computer and use it in GitHub Desktop.
Block specific countries on public facing pages.
<?php
/**
* Drop-in for IP Geo Block custom filters
*
* This file should be renamed to `drop-in.php`.
*
* @package IP_Geo_Block
* @author tokkonopapa <tokkonopapa@yahoo.com>
* @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' );
@tokkonopapa
Copy link
Author

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/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment