/** * @group external-http */ function testUpdate() { $s = new \YellowTree\GeoipDetect\DataSources\Auto\AutoDataSource(); $this->assertTrue($s->maxmindUpdate()); $record = geoip_detect2_get_info_from_ip(GEOIP_DETECT_TEST_IP); $this->assertValidGeoIP2Record($record, GEOIP_DETECT_TEST_IP); }
/** * @deprecated If you really need to do that manually, use the AutoDataSource-Class instead. */ function geoip_detect_update() { _doing_it_wrong('GeoIP Detection: geoip_detect_update', ' If you really need to do that manually, use the AutoDataSource-Class instead.', '2.4.0'); $s = new \YellowTree\GeoipDetect\DataSources\Auto\AutoDataSource(); return $s->maxmindUpdate(); }
function geoip_detect_option_page() { if (!current_user_can('manage_options')) { return; } $registry = DataSourceRegistry::getInstance(); $sources = $registry->getAllSources(); $currentSource = $registry->getCurrentSource(); $message = ''; $numeric_options = array('set_css_country', 'has_reverse_proxy', 'disable_pagecache'); $text_options = array('external_ip'); $option_names = array_merge($numeric_options, $text_options); if (geoip_detect_verify_nonce()) { switch (@$_POST['action']) { case 'update': $registry->setCurrentSource('auto'); $s = new \YellowTree\GeoipDetect\DataSources\Auto\AutoDataSource(); $ret = $s->maxmindUpdate(); if ($ret === true) { $message .= __('Updated successfully.', 'geoip-detect'); } else { $message .= __('Update failed.', 'geoip-detect') . ' ' . $ret; } break; case 'choose': $registry->setCurrentSource($_POST['options']['source']); $currentSource = $registry->getCurrentSource(); break; case 'options-source': $messages = array(); foreach ($sources as $s) { $ret = $s->saveParameters($_POST); if (is_string($ret) && $ret) { $messages[] = $ret; } } if ($messages) { $message .= implode('<br />', $messages); } break; case 'options': // Empty IP Cache delete_transient('geoip_detect_external_ip'); if (!empty($_POST['options']['external_ip'])) { if (!geoip_detect_is_ip($_POST['options']['external_ip'])) { $message .= 'The external IP "' . esc_html($_POST['options']['external_ip']) . '" is not a valid IP.'; unset($_POST['options']['external_ip']); } else { if (!geoip_detect_is_public_ip($_POST['options']['external_ip'])) { $message .= 'Warning: The external IP "' . esc_html($_POST['options']['external_ip']) . '" is not a public internet IP, so it will probably not work.'; } } } foreach ($option_names as $opt_name) { if (in_array($opt_name, $numeric_options)) { $opt_value = isset($_POST['options'][$opt_name]) ? (int) $_POST['options'][$opt_name] : 0; } else { $opt_value = isset($_POST['options'][$opt_name]) ? $_POST['options'][$opt_name] : ''; } update_option('geoip-detect-' . $opt_name, $opt_value); } break; } } $wp_options = array(); foreach ($option_names as $opt_name) { $wp_options[$opt_name] = get_option('geoip-detect-' . $opt_name); } $ipv6_supported = GEOIP_DETECT_IPV6_SUPPORTED; include_once GEOIP_PLUGIN_DIR . '/views/options.php'; }