Post Views Counter - Version 1.2.12

Version Description

  • New: GDPR compatibility with Cookie Notice plugin
Download this release

Release Info

Developer dfactory
Plugin Icon 128x128 Post Views Counter
Version 1.2.12
Comparing to
See all releases

Code changes from version 1.2.11 to 1.2.12

Files changed (3) hide show
  1. includes/counter.php +57 -24
  2. post-views-counter.php +4 -4
  3. readme.txt +9 -4
includes/counter.php CHANGED
@@ -111,30 +111,7 @@ class Post_Views_Counter_Counter {
111
  if ( $count_visit ) {
112
  // strict counts?
113
  if ( Post_Views_Counter()->options['general']['strict_counts'] ) {
114
- // get IP cached visits
115
- $ip_cache = get_transient( 'post_views_counter_ip_cache' );
116
-
117
- if ( ! $ip_cache )
118
- $ip_cache = array();
119
-
120
- // visit exists in transient?
121
- if ( isset( $ip_cache[$id][$user_ip] ) ) {
122
- if ( $current_time > $ip_cache[$id][$user_ip] + $this->get_timestamp( Post_Views_Counter()->options['general']['time_between_counts']['type'], Post_Views_Counter()->options['general']['time_between_counts']['number'], false ) )
123
- $ip_cache[$id][$user_ip] = $current_time;
124
- else
125
- return;
126
- } else
127
- $ip_cache[$id][$user_ip] = $current_time;
128
-
129
- // keep it light, only 10 records per post and maximum 100 post records (=> max. 1000 ip entries)
130
- // also, the data gets deleted after a week if there's no activity during this time...
131
- if ( count( $ip_cache[$id] ) > 10 )
132
- $ip_cache[$id] = array_slice( $ip_cache[$id], -10, 10, true );
133
-
134
- if ( count( $ip_cache ) > 100 )
135
- $ip_cache = array_slice( $ip_cache, -100, 100, true );
136
-
137
- set_transient( 'post_views_counter_ip_cache', $ip_cache, WEEK_IN_SECONDS );
138
  }
139
 
140
  return $this->count_visit( $id );
@@ -265,6 +242,18 @@ class Post_Views_Counter_Counter {
265
  * @param bool $expired
266
  */
267
  private function save_cookie( $id, $cookie = array(), $expired = true ) {
 
 
 
 
 
 
 
 
 
 
 
 
268
  $expiration = $this->get_timestamp( Post_Views_Counter()->options['general']['time_between_counts']['type'], Post_Views_Counter()->options['general']['time_between_counts']['number'] );
269
 
270
  // assign cookie name
@@ -339,6 +328,50 @@ class Post_Views_Counter_Counter {
339
  }
340
  }
341
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
 
343
  /**
344
  * Count visit function.
111
  if ( $count_visit ) {
112
  // strict counts?
113
  if ( Post_Views_Counter()->options['general']['strict_counts'] ) {
114
+ $this->save_ip( $id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
116
 
117
  return $this->count_visit( $id );
242
  * @param bool $expired
243
  */
244
  private function save_cookie( $id, $cookie = array(), $expired = true ) {
245
+ $set_cookie = apply_filters( 'pvc_maybe_set_cookie', true );
246
+
247
+ // Cookie Notice compatibility
248
+ if ( function_exists( 'cn_cookies_accepted' ) ) {
249
+ if ( ! cn_cookies_accepted() ) {
250
+ $set_cookie = false;
251
+ }
252
+ }
253
+
254
+ if ( $set_cookie != true )
255
+ return $id;
256
+
257
  $expiration = $this->get_timestamp( Post_Views_Counter()->options['general']['time_between_counts']['type'], Post_Views_Counter()->options['general']['time_between_counts']['number'] );
258
 
259
  // assign cookie name
328
  }
329
  }
330
  }
331
+
332
+ /**
333
+ * Save user IP function.
334
+ *
335
+ * @param int $id
336
+ */
337
+ private function save_ip( $id ) {
338
+ $set_cookie = apply_filters( 'pvc_maybe_set_cookie', true );
339
+
340
+ // Cookie Notice compatibility
341
+ if ( function_exists( 'cn_cookies_accepted' ) ) {
342
+ if ( ! cn_cookies_accepted() ) {
343
+ $set_cookie = false;
344
+ }
345
+ }
346
+
347
+ if ( $set_cookie != true )
348
+ return $id;
349
+
350
+ // get IP cached visits
351
+ $ip_cache = get_transient( 'post_views_counter_ip_cache' );
352
+
353
+ if ( ! $ip_cache )
354
+ $ip_cache = array();
355
+
356
+ // visit exists in transient?
357
+ if ( isset( $ip_cache[$id][$user_ip] ) ) {
358
+ if ( $current_time > $ip_cache[$id][$user_ip] + $this->get_timestamp( Post_Views_Counter()->options['general']['time_between_counts']['type'], Post_Views_Counter()->options['general']['time_between_counts']['number'], false ) )
359
+ $ip_cache[$id][$user_ip] = $current_time;
360
+ else
361
+ return;
362
+ } else
363
+ $ip_cache[$id][$user_ip] = $current_time;
364
+
365
+ // keep it light, only 10 records per post and maximum 100 post records (=> max. 1000 ip entries)
366
+ // also, the data gets deleted after a week if there's no activity during this time...
367
+ if ( count( $ip_cache[$id] ) > 10 )
368
+ $ip_cache[$id] = array_slice( $ip_cache[$id], -10, 10, true );
369
+
370
+ if ( count( $ip_cache ) > 100 )
371
+ $ip_cache = array_slice( $ip_cache, -100, 100, true );
372
+
373
+ set_transient( 'post_views_counter_ip_cache', $ip_cache, WEEK_IN_SECONDS );
374
+ }
375
 
376
  /**
377
  * Count visit function.
post-views-counter.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Post Views Counter
4
  Description: Post Views Counter allows you to display how many times a post, page or custom post type had been viewed in a simple, fast and reliable way.
5
- Version: 1.2.11
6
  Author: dFactory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/post-views-counter/
@@ -12,7 +12,7 @@ Text Domain: post-views-counter
12
  Domain Path: /languages
13
 
14
  Post Views Counter
15
- Copyright (C) 2014-2017, Digital Factory - info@digitalfactory.pl
16
 
17
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
18
 
@@ -31,7 +31,7 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
31
  * Post Views Counter final class.
32
  *
33
  * @class Post_Views_Counter
34
- * @version 1.2.11
35
  */
36
  final class Post_Views_Counter {
37
 
@@ -81,7 +81,7 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
81
  'link_to_post' => true,
82
  'icon_class' => 'dashicons-chart-bar'
83
  ),
84
- 'version' => '1.2.11'
85
  );
86
 
87
  /**
2
  /*
3
  Plugin Name: Post Views Counter
4
  Description: Post Views Counter allows you to display how many times a post, page or custom post type had been viewed in a simple, fast and reliable way.
5
+ Version: 1.2.12
6
  Author: dFactory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/post-views-counter/
12
  Domain Path: /languages
13
 
14
  Post Views Counter
15
+ Copyright (C) 2014-2018, Digital Factory - info@digitalfactory.pl
16
 
17
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
18
 
31
  * Post Views Counter final class.
32
  *
33
  * @class Post_Views_Counter
34
+ * @version 1.2.12
35
  */
36
  final class Post_Views_Counter {
37
 
81
  'link_to_post' => true,
82
  'icon_class' => 'dashicons-chart-bar'
83
  ),
84
+ 'version' => '1.2.12'
85
  );
86
 
87
  /**
readme.txt CHANGED
@@ -3,8 +3,9 @@ Contributors: dfactory
3
  Donate link: http://www.dfactory.eu/
4
  Tags: counter, hits, posts, postviews, post views, views, count, statistics, stats, analytics, pageviews, tracking
5
  Requires at least: 4.0
6
- Tested up to: 4.9.2
7
- Stable tag: 1.2.11
 
8
  License: MIT License
9
  License URI: http://opensource.org/licenses/MIT
10
 
@@ -20,6 +21,7 @@ For more information, check out plugin page at [dFactory](http://www.dfactory.eu
20
 
21
  * Option to select post types for which post views will be counted and displayed.
22
  * 3 methods of collecting post views data: PHP, Javascript or REST API for greater flexibility
 
23
  * Possibility to manually set views count for each post
24
  * Dashboard post views stats widget
25
  * Capability to query posts according to its views count
@@ -60,6 +62,9 @@ No questions yet.
60
 
61
  == Changelog ==
62
 
 
 
 
63
  = 1.2.11 =
64
  * Tweak: Additional IP expiration checks added as an option
65
 
@@ -172,5 +177,5 @@ Initial release
172
 
173
  == Upgrade Notice ==
174
 
175
- = 1.2.11 =
176
- * Tweak: Additional IP expiration checks added as an option
3
  Donate link: http://www.dfactory.eu/
4
  Tags: counter, hits, posts, postviews, post views, views, count, statistics, stats, analytics, pageviews, tracking
5
  Requires at least: 4.0
6
+ Requires PHP: 5.2.4
7
+ Tested up to: 4.9.6
8
+ Stable tag: 1.2.12
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
11
 
21
 
22
  * Option to select post types for which post views will be counted and displayed.
23
  * 3 methods of collecting post views data: PHP, Javascript or REST API for greater flexibility
24
+ * GDPR compatibility with [Cookie Notice](https://wordpress.org/plugins/cookie-notice/) plugin
25
  * Possibility to manually set views count for each post
26
  * Dashboard post views stats widget
27
  * Capability to query posts according to its views count
62
 
63
  == Changelog ==
64
 
65
+ = 1.2.12 =
66
+ * New: GDPR compatibility with Cookie Notice plugin
67
+
68
  = 1.2.11 =
69
  * Tweak: Additional IP expiration checks added as an option
70
 
177
 
178
  == Upgrade Notice ==
179
 
180
+ = 1.2.12 =
181
+ * New: GDPR compatibility with Cookie Notice plugin