Skip to content

Commit 159087c

Browse files
author
Benjamin Pick
committed
Recommended Fixes from Plugin Checker
1 parent 7e8ea57 commit 159087c

File tree

12 files changed

+101
-108
lines changed

12 files changed

+101
-108
lines changed

admin-ui.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function geoip_detect_option_page() {
195195
break;
196196

197197
case 'choose':
198-
$sourceId = sanitize_text_field($_POST['options']['source']);
198+
$sourceId = sanitize_text_field(isset($_POST['options']['source']) ? $_POST['options']['source'] : '' );
199199
$registry->setCurrentSource($sourceId);
200200
break;
201201

@@ -219,7 +219,7 @@ function geoip_detect_option_page() {
219219
if (in_array($opt_name, $numeric_options))
220220
$opt_value = isset($_POST['options'][$opt_name]) ? (int) $_POST['options'][$opt_name] : 0;
221221
else {
222-
$opt_value = geoip_detect_sanitize_option($opt_name, @$_POST['options'][$opt_name], $m);
222+
$opt_value = geoip_detect_sanitize_option($opt_name, isset($_POST['options'][$opt_name]) ? $_POST['options'][$opt_name] : '', $m);
223223
}
224224
if ($m) {
225225
$messages[] = $m;

ajax.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function geoip_detect_ajax_get_info_from_current_ip() {
4949

5050
// Referer check
5151

52-
$referer = _geoip_detect_get_domain_name($_SERVER['HTTP_REFERER']);
52+
$referer = _geoip_detect_get_domain_name(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
5353
if (!$referer) {
5454
_geoip_detect_ajax_error('This AJAX call does not work when called directly. Do an AJAX call via JS instead.');
5555
}
@@ -75,7 +75,7 @@ function geoip_detect_ajax_get_info_from_current_ip() {
7575

7676

7777
function _geoip_detect_get_domain_name($url) {
78-
$result = parse_url($url);
78+
$result = wp_parse_url($url);
7979
return $result['host'];
8080
}
8181

check_compatibility.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ function checkCompatible() {
9696
$line2 = __('These incompatible files have been found to be loaded from another plugin: ', 'geoip-detect') . $data;
9797
$line3 = __('Please test if looking up an IP adress works without an PHP Error. If it works, you can dismiss this notice. It will appear again when their libraries are changed.', 'geoip-detect');
9898

99-
$body = <<<BODY
99+
$body = "
100100
<p><i>$line1</i></p>
101101
<p>$line2</p>
102102
<p>$line3</p>
103-
BODY;
103+
";
104104
$this->adminNotices[] = [
105105
'id' => 'maxmind_vendor_old_' . md5($data),
106106
'title' => __('Geolocation IP Detection: Warning: Old Maxmind Libraries detected.', 'geoip-detect'),

data-sources/auto.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function saveParameters($post) {
143143

144144
protected function download_url($url, $modified = 0) {
145145
// Similar to wordpress download_url, but with custom UA
146-
$url_filename = basename( parse_url( $url, PHP_URL_PATH ) );
146+
$url_filename = basename( wp_parse_url( $url, PHP_URL_PATH ) );
147147

148148
$tmpfname = wp_tempnam( $url_filename );
149149
if ( ! $tmpfname )
@@ -161,7 +161,7 @@ protected function download_url($url, $modified = 0) {
161161
return new \WP_Error( 'http_304', __('It has not changed since the last update.', 'geoip-detect') );
162162
}
163163
if (is_wp_error( $response ) || 200 != $http_response_code) {
164-
unlink($tmpfname);
164+
wp_delete_file($tmpfname);
165165
$body = wp_remote_retrieve_body($response);
166166
return new \WP_Error( 'http_404', $http_response_code . ': ' . trim( wp_remote_retrieve_response_message( $response ) ) . ' ' . $body );
167167
}
@@ -220,7 +220,7 @@ public function maxmindUpdate($forceUpdate = false)
220220
}
221221

222222
update_option('geoip-detect-auto_downloaded_file', '');
223-
unlink($tmpFile);
223+
wp_delete_file($tmpFile);
224224

225225
return true;
226226
}
@@ -252,7 +252,7 @@ protected function unpackArchive($downloadedFilename, $outFile) {
252252
$phar->extractTo($outDir, null, true);
253253
} catch(\Throwable $e) {
254254
// Fallback method of unpacking?
255-
unlink($downloadedFilename); // Do not try to unpack this file again, instead re-download
255+
wp_delete_file($downloadedFilename); // Do not try to unpack this file again, instead re-download
256256
return __('The downloaded file seems to be corrupt. Try again ...', 'geoip-detect');
257257
}
258258

@@ -309,7 +309,7 @@ public function set_cron_schedule()
309309
public function schedule_next_cron_run() {
310310
// Try to update every 1-2 weeks
311311
$next = time() + WEEK_IN_SECONDS;
312-
$next += mt_rand(1, WEEK_IN_SECONDS);
312+
$next += \wp_rand(1, WEEK_IN_SECONDS);
313313

314314
wp_schedule_single_event($next, 'geoipdetectupdate');
315315
}
@@ -329,7 +329,7 @@ public function uninstall() {
329329
// Delete the automatically downloaded file, if it exists
330330
$filename = $this->maxmindGetFilename();
331331
if ($filename) {
332-
unlink($filename);
332+
wp_delete_file($filename);
333333
}
334334
}
335335
}

geoip-detect.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
License: GPLv3 or later
1010
License URI: http://www.gnu.org/licenses/gpl-3.0.html
1111
Text Domain: geoip-detect
12-
Domain Path: /languages
1312
GitHub Plugin URI: https://github.com/yellowtree/geoip-detect
1413
GitHub Branch: master
1514
Requires WP: 5.4

init.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ function geoip_detect_check_ipv6_support() {
3636
return @inet_pton('::1') !== false;
3737
}
3838

39-
// Load Locales
40-
function geoip_detect_load_textdomain() {
41-
load_plugin_textdomain( 'geoip-detect', false, GEOIP_PLUGIN_DIR . '/languages' );
42-
}
43-
add_action( 'init', 'geoip_detect_load_textdomain' );
44-
4539

4640
function geoip_detect_enqueue_admin_notices() {
4741
// Nobody would see these notices them anyway.
@@ -89,15 +83,15 @@ function geoip_detect_admin_notice_template($id, $title, $body, $addButtonDismis
8983
?>
9084
<div class="error notice is-dismissible">
9185
<p style="float: right">
92-
<a href="tools.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>&geoip_detect_dismiss_notice=<?php echo $id ?>"><?php _e('Dismiss notice', 'geoip-detect'); ?></a>
86+
<a href="tools.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>&geoip_detect_dismiss_notice=<?php echo esc_attr($id) ?>"><?php _e('Dismiss notice', 'geoip-detect'); ?></a>
9387
</p>
9488

9589
<h3><?php echo $title; ?></h3>
9690

9791
<?php echo $body; ?>
9892
<?php if ($addButtonDismiss) : ?>
9993
<p>
100-
<a class="button button-secondary" href="?geoip_detect_dismiss_notice=<?= $id ?>">Hide this notice</a>
94+
<a class="button button-secondary" href="?geoip_detect_dismiss_notice=<?php echo esc_attr($id) ?>">Hide this notice</a>
10195
</p>
10296
<?php endif; ?>
10397
</div>

lib/ccpa.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function schedule($forceReschedule = false) {
288288

289289
protected function schedule_next_cron_run() {
290290
$next = time() + DAY_IN_SECONDS;
291-
$next += mt_rand(1, HOUR_IN_SECONDS);
291+
$next += wp_rand(1, HOUR_IN_SECONDS);
292292
wp_schedule_single_event($next, 'geoipdetectccpaupdate');
293293
}
294294
}

lib/dynamic-reverse-proxies/abstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function unschedule() {
168168

169169
protected function schedule_next_cron_run() {
170170
$next = time() + DAY_IN_SECONDS;
171-
$next += mt_rand(1, HOUR_IN_SECONDS);
171+
$next += wp_rand(1, HOUR_IN_SECONDS);
172172
wp_schedule_single_event($next, 'geoipdetectdynamicproxiesupdate');
173173
}
174174
}

readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Contributors: benjaminpick
33
Tags: geolocation, locator, geoip, maxmind, ipstack
44
Requires at least: 5.0
5-
Tested up to: 6.7
6-
Requires PHP: 7.2
5+
Tested up to: 6.8
6+
Requires PHP: 7.2.5
77
Stable tag: 5.5.0
88
License: GPLv3 or later
99
License URI: http://www.gnu.org/licenses/gpl-3.0.html

views/client-ip.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
</span>
3737
</p>
3838
<p>
39-
REMOTE_ADDR: <b><?php echo $_SERVER['REMOTE_ADDR']; ?></b><br>
39+
REMOTE_ADDR: <b><?php echo esc_html($_SERVER['REMOTE_ADDR']); ?></b><br>
4040
<span class="detail-box">In server configurations without reverse proxy, this will equal to the "detected client IP". Otherwise, this is the IP of the reverse proxy.</span>
41-
HTTP_X_FORWARDED_FOR: <b><?php echo isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : __('(unset)', 'geoip-detect'); ?></b><br>
41+
HTTP_X_FORWARDED_FOR: <b><?php echo isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? esc_html($_SERVER["HTTP_X_FORWARDED_FOR"]) : __('(unset)', 'geoip-detect'); ?></b><br>
4242
<span class="detail-box">Reverse proxies usually add this header to indicate the original IP. If several IPs are given here (seperated by a comma), the correct user IP usually is the leftmost one.</span>
4343
<?php if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && !get_option('geoip-detect-has_reverse_proxy')): ?>
4444
<i>(Probably you should enable the reverse proxy option.)</i>
@@ -56,10 +56,10 @@
5656

5757
<li>Add known proxies of a cloud provider enabled: <b><?php echo get_option('geoip-detect-dynamic_reverse_proxies') ? 'Yes, ' . ucfirst(get_option('geoip-detect-dynamic_reverse_proxy_type', '')) : 'No'; ?></b>
5858
<span class="detail-box">If your site is hosted by CloudFlare or AWS, this should probably be enabled. It will automatically retrieve the many IP adresses that a reverse proxy of this provider can have, and update the list daily.</span>
59-
<span class="detail-box">Here is the current list of IP adresses: <b><?= implode(', ', \YellowTree\GeoipDetect\DynamicReverseProxies\addDynamicIps()) ?: '(Empty)' ?></b></span>
59+
<span class="detail-box">Here is the current list of IP adresses: <b><?php echo implode(', ', \YellowTree\GeoipDetect\DynamicReverseProxies\addDynamicIps()) ?: '(Empty)' ?></b></span>
6060
<span class="detail-box">
61-
Last updated: <b><?= geoip_detect_format_localtime($last_update); ?></b><br>
62-
Next update: <b><?= geoip_detect_format_localtime(wp_next_scheduled('geoipdetectdynamicproxiesupdate')); ?></b>
61+
Last updated: <b><?php echo geoip_detect_format_localtime($last_update); ?></b><br>
62+
Next update: <b><?php echo geoip_detect_format_localtime(wp_next_scheduled('geoipdetectdynamicproxiesupdate')); ?></b>
6363
<?php if(get_option('geoip-detect-dynamic_reverse_proxies')) : ?>
6464
<form method="POST">
6565
<?php wp_nonce_field( 'geoip_detect_reload-proxies' ); ?>

0 commit comments

Comments
 (0)