Skip to content

Commit

Permalink
version bump to 1.8 and fixed the validate_ip function
Browse files Browse the repository at this point in the history
  • Loading branch information
vanpariyar committed Dec 19, 2021
1 parent 427daf9 commit ff68697
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion includes/shortcodes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

add_action( 'wp', 'wppv_add_custom_shortcode' );
add_action( 'init', 'wppv_add_custom_shortcode' );
function wppv_add_custom_shortcode() {
/**
* @param $post which is Post id ( Optional )
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: post views, count wordpress site views, show post views, post view counter
Requires at least: 5.0
Requires PHP: 5.3
Tested up to: 5.8
Stable tag: 1.7
Stable tag: 1.8
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -46,6 +46,10 @@ Use this shortcode.

== Changelog ==

= 1.8 - 19/12/2021 =
- Version Bump to 5.8
- Fix `validate_ip()` function creates error.

= 1.6 & 1.7 - 14/07/2020 =
- Version bump to 5.8

Expand Down
14 changes: 7 additions & 7 deletions wp-post-views.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: WP Post Views
* Plugin URI: https://github.com/vanpariyar/wp-post-views
* Description: WP Post Views.
* Version: 1.7
* Version: 1.8
* Requires at least: 5.0
* Requires PHP: 5.3
* Author: Ronak J Vanpariya
Expand Down Expand Up @@ -89,24 +89,24 @@ public function wppv_posts_custom_column_views( $column ) {
public function get_ip_address()
{
// check for shared internet/ISP IP
if (!empty($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP']))
if (!empty($_SERVER['HTTP_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_CLIENT_IP']))
return $_SERVER['HTTP_CLIENT_IP'];
// check for IPs passing through proxies
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// check if multiple ips exist in var
$iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
foreach ($iplist as $ip) {
if (validate_ip($ip))
if ($this->validate_ip($ip))
return $ip;
}
}
if (!empty($_SERVER['HTTP_X_FORWARDED']) && validate_ip($_SERVER['HTTP_X_FORWARDED']))
if (!empty($_SERVER['HTTP_X_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_X_FORWARDED']))
return $_SERVER['HTTP_X_FORWARDED'];
if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && validate_ip($_SERVER['HTTP_FORWARDED_FOR']))
if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->validate_ip($_SERVER['HTTP_FORWARDED_FOR']))
return $_SERVER['HTTP_FORWARDED_FOR'];
if (!empty($_SERVER['HTTP_FORWARDED']) && validate_ip($_SERVER['HTTP_FORWARDED']))
if (!empty($_SERVER['HTTP_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_FORWARDED']))
return $_SERVER['HTTP_FORWARDED'];
// return unreliable ip since all else failed
return $_SERVER['REMOTE_ADDR'];
Expand Down

0 comments on commit ff68697

Please sign in to comment.