Created WC_Geo_IP class

This commit is contained in:
Claudio Sanches 2015-02-11 15:51:50 -02:00
parent 3e9f06a8eb
commit 5389dc3812
2 changed files with 1731 additions and 6 deletions

1723
includes/class-wc-geo-ip.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -170,13 +170,15 @@ class WC_Geolocation {
* @return string
*/
private static function geolocate_via_db( $ip_address ) {
if ( ! class_exists( 'GeoIP' ) && ! class_exists( 'geoiprecord' ) ) {
include_once( 'libraries/geoip.php' );
if ( ! class_exists( 'WC_Geo_IP' ) ) {
include_once( 'class-wc-geo-ip.php' );
}
$database = self::get_local_database_path();
$gi = geoip_open( $database, GEOIP_STANDARD );
$country_code = geoip_country_code_by_addr( $gi, $ip_address );
geoip_close( $gi );
$database = self::get_local_database_path();
$gi = new WC_Geo_IP();
$gi->geoip_open( $database, 0 );
$country_code = $gi->geoip_country_code_by_addr( $ip_address );
$gi->geoip_close();
return sanitize_text_field( strtoupper( $country_code ) );
}