get_results("SELECT id,ip FROM `{$wpdb->prefix}statistics_visitor` WHERE location = '' or location = '000' or location IS NULL");
// Try create a new reader instance.
try {
$upload_dir = wp_upload_dir();
$reader = new Reader( $upload_dir['basedir'] . '/wp-statistics/GeoLite2-Country.mmdb' );
} catch( Exception $e ) {
return "
" . __('Unable to load the GeoIP database, make sure you have downloaded it in the settings page.', 'wp_statistics') . "
";
}
$count = 0;
// Loop through all the missing rows and update them if we find a locaiton for them.
foreach( $result as $item ) {
$count++;
// If the IP address is only a hash, don't bother updating the record.
if( substr( $item->ip, 0, 6 ) != '#hash#' ) {
try {
$record = $reader->country( $item->ip );
$location = $record->country->isoCode;
if( $location == "" ) { $location = "000"; }
} catch( Exception $e ) {
$location = "000";
}
// Update the row in the database.
$wpdb->update( $wpdb->prefix . "statistics_visitor", array( 'location' => $location ), array( 'id' => $item->id) );
}
}
return "" . sprintf(__('Updated %s GeoIP records in the visitors database.', 'wp_statistics'), $count) . "
";
}
?>