forked from yellowtree/geoip-detect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.php
More file actions
90 lines (70 loc) · 3.48 KB
/
Copy pathinit.php
File metadata and controls
90 lines (70 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
function geoip_detect_defines() {
if (!defined('GEOIP_DETECT_IP_CACHE_TIME'))
define('GEOIP_DETECT_IP_CACHE_TIME', 2 * HOUR_IN_SECONDS);
if (!defined('GEOIP_DETECT_READER_CACHE_TIME'))
define('GEOIP_DETECT_READER_CACHE_TIME', 7 * DAY_IN_SECONDS);
if (!defined('GEOIP_DETECT_DOING_UNIT_TESTS'))
define('GEOIP_DETECT_DOING_UNIT_TESTS', false);
if (!defined('GEOIP_DETECT_IPV6_SUPPORTED'))
define('GEOIP_DETECT_IPV6_SUPPORTED', defined('AF_INET6'));
}
add_action('plugins_loaded', 'geoip_detect_defines');
function geoip_detect_enqueue_admin_notices() {
// Nobody would see them anyway.
if (!is_admin() ||
!is_user_logged_in() ||
(defined('DOING_CRON') && DOING_CRON) ||
(defined('DOING_AJAX') && DOING_AJAX) )
return;
global $plugin_page;
if (get_option('geoip-detect-source') == 'hostinfo' && get_option('geoip-detect-ui-has-chosen-source', false) == false) {
if ($plugin_page == GEOIP_PLUGIN_BASENAME && isset($_POST['action']) && $_POST['action'] == 'update') {
// Skip because maybe he is currently updating the database
} else {
add_action( 'all_admin_notices', 'geoip_detect_admin_notice_database_missing' );
}
}
}
add_action('admin_init', 'geoip_detect_enqueue_admin_notices');
function geoip_detect_admin_notice_database_missing() {
$ignored_notices = (array) get_user_meta(get_current_user_id(), 'geoip_detect_dismissed_notices', true);
if (in_array('hostinfo_used', $ignored_notices))
return;
$url = '<a href="tools.php?page=' . GEOIP_PLUGIN_BASENAME . '">GeoIP Detection</a>';
?>
<div class="error">
<p style="float: right">
<a href="tools.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>&geoip_detect_dismiss_notice=hostinfo_used"><?php _e('Dismiss notice', 'geoip-detect'); ?></a>
<h3><?php _e( 'GeoIP Detection: No database installed', 'geoip-detect' ); ?></h3>
<p><?php printf(__('The Plugin %s is currently using the Webservice <a href="http://hostip.info" target="_blank">hostip.info</a> as data source. <br />You can click on the button below to download and install Maxmind GeoIPv2 Lite City now.', 'geoip-detect' ), $url); ?></p>
<p><?php printf(__('This database is licenced <a href="http://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA</a>. See <a href="http://dev.maxmind.com/geoip/geoip2/geolite2/#License">License</a> for details.')); ?>
<form action="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME; ?>" method="post">
<?php wp_nonce_field( 'geoip_detect_update' ); ?>
<input type="hidden" name="source" value="auto" />
<input type="hidden" name="action" value="update" />
<p>
<input type="submit" value="Install now" class="button button-primary" />
<a href="?geoip_detect_dismiss_notice=hostinfo_used"><?php _e('Keep using hostip.info', 'geoip-detect'); ?></a>
</p>
</form>
</div>
<?php
}
function geoip_detect_dismiss_message() {
if (!is_admin() || !is_user_logged_in())
return;
if (!isset($_GET['geoip_detect_dismiss_notice']))
return;
$dismiss = $_GET['geoip_detect_dismiss_notice'];
if ($dismiss) {
$ignored_notices = (array) get_user_meta(get_current_user_id(), 'geoip_detect_dismissed_notices', true);
if ($dismiss == '-1') { // Undocumented feature: reset dismissed messages
$ignored_notices = array();
} else if (!in_array($dismiss, $ignored_notices)) {
$ignored_notices[] = $dismiss;
}
update_user_meta(get_current_user_id(), 'geoip_detect_dismissed_notices', $ignored_notices);
}
}
add_action('admin_init', 'geoip_detect_dismiss_message');