function testUpdate() { $this->assertTrue(geoip_detect_update()); $record = geoip_detect_get_info_from_ip(GEOIP_DETECT_TEST_IP); $this->assertValidGeoIPRecord($record, GEOIP_DETECT_TEST_IP); $record = geoip_detect_get_info_from_ip('192.168.1.1'); $this->assertValidGeoIPRecord($record, '192.168.1.1'); }
function geoip_detect_update_cron($immediately_after_activation = false) { /** * Filter: * Cron has fired. * Find out if file should be updated now. * * @param $do_it False if deactivated by define * @param $immediately_after_activation True if this is fired because the plugin was recently activated */ $do_it = apply_filters('geoip_detect_cron_do_update', !GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED, $immediately_after_activation); if ($do_it) { geoip_detect_update(); } geoip_detect_schedule_next_cron_run(); }
function geoip_detect_plugin_page() { geoip_detect_set_cron_schedule(); $ip_lookup_result = false; $last_update = 0; $message = ''; switch (@$_POST['action']) { case 'update': $ret = geoip_detect_update(); if ($ret === true) { $message .= __('Updated successfully.', 'geoip-detect'); } else { $message .= __('Update failed.', 'geoip-detect') . ' ' . $ret; } break; case 'lookup': if (isset($_POST['ip'])) { $ip = $_POST['ip']; $ip_lookup_result = geoip_detect_get_info_from_ip($ip); } break; case 'options': $opt_value = isset($_POST['options']['set_css_country']) ? (int) $_POST['options']['set_css_country'] : 0; update_option('geoip-detect-set_css_country', $opt_value); $opt_value = isset($_POST['options']['data_filename']) ? $_POST['options']['data_filename'] : 'GeoLiteCity.dat'; update_option('geoip-detect-data_filename', $opt_value); break; } $data_file = geoip_detect_get_abs_db_filename(); if (file_exists($data_file)) { $last_update = filemtime($data_file); } else { $message .= __('No GeoIP Database found. Click on the button "Update now" or follow the installation instructions.', 'geoip-detect'); $last_update = 0; } if (empty($custom_filename)) { $next_cron_update = wp_next_scheduled('geoipdetectupdate'); } $options = array(); $options['set_css_country'] = (int) get_option('geoip-detect-set_css_country'); $options['data_filename'] = get_option('geoip-detect-data_filename'); include_once dirname(__FILE__) . '/views/plugin_page.php'; }