Skip to content

Commit

Permalink
Fixed some IP related issues 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
Antontokarchuk0302 committed Mar 5, 2021
1 parent 3598a89 commit f286605
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@ 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

mysql:
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
6 changes: 3 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
36 changes: 21 additions & 15 deletions wp-post-views.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit f286605

Please sign in to comment.