From f286605bbb2a897295ac5d0d84c28c1c008a633b Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 5 Mar 2021 18:02:41 +0530 Subject: [PATCH] Fixed some IP related issues :bug: --- docker-compose.yml | 16 ++++++++++++++++ readme.txt | 6 +++--- wp-post-views.php | 36 +++++++++++++++++++++--------------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4c63bd7..1765d26 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,6 +8,10 @@ services: - 9999:80 environment: WORDPRESS_DB_PASSWORD: example + WORDPRESS_CONFIG_EXTRA: + define( 'WP_DEBUG', true ); + + volumes: - ./:/var/www/html/wp-content/plugins/wp-post-views @@ -15,3 +19,15 @@ services: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: example + + # phpmyadmin + phpmyadmin: + depends_on: + - mysql + image: phpmyadmin/phpmyadmin + restart: always + ports: + - '9998:80' + environment: + PMA_HOST: mysql + MYSQL_ROOT_PASSWORD: example \ No newline at end of file diff --git a/readme.txt b/readme.txt index c0b5c40..78361c8 100644 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,10 @@ === Wp Post Views - Wordpress Post views counter === Contributors: vanpariyar, ankitatanti, Brijeshdhanani, Tags: post views, count wordpress site views, show post views, post view counter, WP Post Views, post view count based on ip -Requires at least: 4.0 +Requires at least: 5.0 Requires PHP: 5.3 -Tested up to: 5.6.0 -Stable tag: 1.4 +Tested up to: 5.7 +Stable tag: 1.5 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html diff --git a/wp-post-views.php b/wp-post-views.php index 2247984..592bd12 100644 --- a/wp-post-views.php +++ b/wp-post-views.php @@ -11,9 +11,9 @@ * Plugin Name: WP Post Views * Plugin URI: https://github.com/vanpariyar/wp-post-views * Description: WP Post Views. - * Version: 1.4 + * Version: 1.5 * Requires at least: 5.0 - * Requires PHP: 5.0 + * Requires PHP: 5.3 * Author: Ronak J Vanpariya * Author URI: https://vanpariyar.github.io * Text Domain: wppv @@ -131,21 +131,27 @@ public function counter(){ if(in_array($post->post_type , $selected_type)){ if ( !empty($options['wppv_api_text_field_1']) ) { $stored_ip_addresses = get_post_meta(get_the_ID(),'view_ip',true); - if($stored_ip_addresses) - { - if(count($stored_ip_addresses)) + + $current_ip = $this->get_ip_address(); + if( $stored_ip_addresses ) + { + if(!in_array($current_ip, $stored_ip_addresses)) { - $current_ip = $this->get_ip_address(); - if(!in_array($current_ip, $stored_ip_addresses)) - { - $meta_key = 'entry_views'; - $view_post_meta = get_post_meta(get_the_ID(), $meta_key, true); - $new_viewed_count = intval($view_post_meta) + 1; - update_post_meta(get_the_ID(), $meta_key, $new_viewed_count); - $stored_ip_addresses[] = $current_ip; - update_post_meta(get_the_ID(),'view_ip',$stored_ip_addresses); - } + $meta_key = 'entry_views'; + $view_post_meta = get_post_meta(get_the_ID(), $meta_key, true); + $new_viewed_count = intval($view_post_meta) + 1; + update_post_meta(get_the_ID(), $meta_key, $new_viewed_count); + $stored_ip_addresses[] = $current_ip; + update_post_meta(get_the_ID(),'view_ip',$stored_ip_addresses); } + } else { + $stored_ip_addresses = array(); + $meta_key = 'entry_views'; + $view_post_meta = get_post_meta(get_the_ID(), $meta_key, true); + $new_viewed_count = intval($view_post_meta) + 1; + update_post_meta(get_the_ID(), $meta_key, $new_viewed_count); + $stored_ip_addresses[] = $current_ip; + update_post_meta(get_the_ID(),'view_ip',$stored_ip_addresses); } } else { $meta_key = 'entry_views';