Post Views Counter - Version 1.2.14

Version Description

  • Fix: Bulk edit post views count reset issue
Download this release

Release Info

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

Code changes from version 1.2.13 to 1.2.14

includes/ajax.php CHANGED
@@ -60,6 +60,22 @@ wp_ssl_constants();
60
  // include Post Views Counter core
61
  require_once( WP_PLUGIN_DIR . '/post-views-counter/post-views-counter.php' );
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  $action = esc_attr( trim( $_POST['action'] ) );
64
 
65
  // a bit of security
60
  // include Post Views Counter core
61
  require_once( WP_PLUGIN_DIR . '/post-views-counter/post-views-counter.php' );
62
 
63
+ // if PVC_SHORTINIT_INC is defined in wp-config.php load theme/pvc/includes.php file
64
+ // this allows to perform custom actions, for example hook into pvc_after_count_visit
65
+ if ( defined( 'PVC_SHORTINIT_INC' ) && PVC_SHORTINIT_INC ) {
66
+ require_once( ABSPATH . WPINC . '/plugin.php' );
67
+ require_once( ABSPATH . WPINC . '/theme.php' );
68
+
69
+ // get the current theme path
70
+ $theme_path = get_theme_file_path();
71
+ // load custom pvc includes file
72
+ $pvc_file_path = $theme_path . DIRECTORY_SEPARATOR . 'pvc' . DIRECTORY_SEPARATOR . 'includes.php';
73
+
74
+ if ( is_file( $pvc_file_path ) ) {
75
+ require_once( $pvc_file_path );
76
+ }
77
+ }
78
+
79
  $action = esc_attr( trim( $_POST['action'] ) );
80
 
81
  // a bit of security
includes/columns.php CHANGED
@@ -84,7 +84,6 @@ class Post_Views_Counter_Columns {
84
  * @param object $post
85
  */
86
  public function save_post( $post_id, $post ) {
87
-
88
  // break if doing autosave
89
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
90
  return $post_id;
@@ -118,13 +117,7 @@ class Post_Views_Counter_Columns {
118
  $count = apply_filters( 'pvc_update_post_views_count', absint( $_POST['post_views'] ), $post_id );
119
 
120
  // insert or update db post views count
121
- $wpdb->query(
122
- $wpdb->prepare( "
123
- INSERT INTO " . $wpdb->prefix . "post_views (id, type, period, count)
124
- VALUES (%d, %d, %s, %d)
125
- ON DUPLICATE KEY UPDATE count = %d", $post_id, 4, 'total', $count, $count
126
- )
127
- );
128
 
129
  do_action( 'pvc_after_update_post_views_count', $post_id );
130
  }
@@ -234,14 +227,12 @@ class Post_Views_Counter_Columns {
234
  if ( $restrict === true && ! current_user_can( apply_filters( 'pvc_restrict_edit_capability', 'manage_options' ) ) )
235
  return;
236
 
237
- // get total post views
238
- $count = $count = pvc_get_post_views( $post->ID );
239
  ?>
240
  <fieldset class="inline-edit-col-left">
241
  <div id="inline-edit-post_views" class="inline-edit-col">
242
  <label class="inline-edit-group">
243
  <span class="title"><?php _e( 'Post Views', 'post-views-counter' ); ?></span>
244
- <span class="input-text-wrap"><input type="text" name="post_views" class="title text" value="<?php echo absint( $count ); ?>"></span>
245
  <?php wp_nonce_field( 'post_views_count', 'pvc_nonce' ); ?>
246
  </label>
247
  </div>
@@ -256,15 +247,31 @@ class Post_Views_Counter_Columns {
256
  * @return type
257
  */
258
  function save_bulk_post_views() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
  $post_ids = ( ! empty( $_POST['post_ids'] ) && is_array( $_POST['post_ids'] ) ) ? array_map( 'absint', $_POST['post_ids'] ) : array();
261
- $count = ( ! empty( $_POST['post_views'] ) ) ? absint( $_POST['post_views'] ) : null;
 
 
262
 
263
  // break if views editing is restricted
264
  $restrict = (bool) Post_Views_Counter()->options['general']['restrict_edit_views'];
265
 
266
  if ( $restrict === true && ! current_user_can( apply_filters( 'pvc_restrict_edit_capability', 'manage_options' ) ) )
267
- die();
268
 
269
  if ( ! empty( $post_ids ) ) {
270
  foreach ( $post_ids as $post_id ) {
@@ -285,7 +292,7 @@ class Post_Views_Counter_Columns {
285
  );
286
  }
287
  }
288
- die();
289
- }
290
 
 
 
291
  }
84
  * @param object $post
85
  */
86
  public function save_post( $post_id, $post ) {
 
87
  // break if doing autosave
88
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
89
  return $post_id;
117
  $count = apply_filters( 'pvc_update_post_views_count', absint( $_POST['post_views'] ), $post_id );
118
 
119
  // insert or update db post views count
120
+ $wpdb->query( $wpdb->prepare( "INSERT INTO " . $wpdb->prefix . "post_views (id, type, period, count) VALUES (%d, %d, %s, %d) ON DUPLICATE KEY UPDATE count = %d", $post_id, 4, 'total', $count, $count ) );
 
 
 
 
 
 
121
 
122
  do_action( 'pvc_after_update_post_views_count', $post_id );
123
  }
227
  if ( $restrict === true && ! current_user_can( apply_filters( 'pvc_restrict_edit_capability', 'manage_options' ) ) )
228
  return;
229
 
 
 
230
  ?>
231
  <fieldset class="inline-edit-col-left">
232
  <div id="inline-edit-post_views" class="inline-edit-col">
233
  <label class="inline-edit-group">
234
  <span class="title"><?php _e( 'Post Views', 'post-views-counter' ); ?></span>
235
+ <span class="input-text-wrap"><input type="text" name="post_views" class="title text" value=""></span>
236
  <?php wp_nonce_field( 'post_views_count', 'pvc_nonce' ); ?>
237
  </label>
238
  </div>
247
  * @return type
248
  */
249
  function save_bulk_post_views() {
250
+ if ( ! isset( $_POST['post_views'] ) ) {
251
+ $count = null;
252
+ } else {
253
+ $count = trim( $_POST['post_views'] );
254
+
255
+ if ( is_numeric( $_POST['post_views'] ) ) {
256
+ $count = (int) $_POST['post_views'];
257
+
258
+ if ( $count < 0 )
259
+ $count = 0;
260
+ } else {
261
+ $count = null;
262
+ }
263
+ }
264
 
265
  $post_ids = ( ! empty( $_POST['post_ids'] ) && is_array( $_POST['post_ids'] ) ) ? array_map( 'absint', $_POST['post_ids'] ) : array();
266
+
267
+ if ( is_null( $count ) )
268
+ exit;
269
 
270
  // break if views editing is restricted
271
  $restrict = (bool) Post_Views_Counter()->options['general']['restrict_edit_views'];
272
 
273
  if ( $restrict === true && ! current_user_can( apply_filters( 'pvc_restrict_edit_capability', 'manage_options' ) ) )
274
+ exit;
275
 
276
  if ( ! empty( $post_ids ) ) {
277
  foreach ( $post_ids as $post_id ) {
292
  );
293
  }
294
  }
 
 
295
 
296
+ exit;
297
+ }
298
  }
includes/settings.php CHANGED
@@ -707,8 +707,8 @@ class Post_Views_Counter_Settings {
707
  $input['exclude_ips'] = array_unique( $ips );
708
  }
709
 
710
- // restrict edit viewa
711
- $input['restrict_edit_views'] = isset( $input['restrict_edit_views'] ) ? $input['restrict_edit_views'] : Post_Views_Counter()->defaults['general']['restrict_edit_views'];
712
 
713
  // strict counts
714
  $input['strict_counts'] = isset( $input['strict_counts'] );
707
  $input['exclude_ips'] = array_unique( $ips );
708
  }
709
 
710
+ // restrict edit views
711
+ $input['restrict_edit_views'] = isset( $input['restrict_edit_views'] );
712
 
713
  // strict counts
714
  $input['strict_counts'] = isset( $input['strict_counts'] );
js/frontend.js CHANGED
@@ -18,9 +18,15 @@
18
  beforeSend: function ( xhr ) {
19
  xhr.setRequestHeader( 'X-WP-Nonce', pvcArgsFrontend.nonce );
20
  }
 
 
 
 
 
 
21
  } );
22
 
23
- // admin ajax or fast ajax request
24
  } else {
25
 
26
  var request = {
@@ -35,6 +41,12 @@
35
  async: true,
36
  cache: false,
37
  data: request
 
 
 
 
 
 
38
  } );
39
 
40
  }
18
  beforeSend: function ( xhr ) {
19
  xhr.setRequestHeader( 'X-WP-Nonce', pvcArgsFrontend.nonce );
20
  }
21
+ } ).done( function( response ) {
22
+ // trigger pvcCheckPost event
23
+ $.event.trigger( {
24
+ type: 'pvcCheckPost',
25
+ detail: response
26
+ } );
27
  } );
28
 
29
+ // admin ajax or fast ajax request
30
  } else {
31
 
32
  var request = {
41
  async: true,
42
  cache: false,
43
  data: request
44
+ } ).done( function( response ) {
45
+ // trigger pvcCheckPost event
46
+ $.event.trigger( {
47
+ type: 'pvcCheckPost',
48
+ detail: response
49
+ } );
50
  } );
51
 
52
  }
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.13
6
  Author: dFactory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/post-views-counter/
@@ -23,7 +23,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
23
 
24
  // exit if accessed directly
25
  if ( ! defined( 'ABSPATH' ) )
26
- exit;
27
 
28
  if ( ! class_exists( 'Post_Views_Counter' ) ) :
29
 
@@ -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.13
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.13'
85
  );
86
 
87
  /**
@@ -114,6 +114,7 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
114
  if ( defined( 'SHORTINIT' ) && SHORTINIT ) {
115
  include_once( POST_VIEWS_COUNTER_PATH . 'includes/counter.php' );
116
  include_once( POST_VIEWS_COUNTER_PATH . 'includes/crawler-detect.php' );
 
117
 
118
  self::$instance->counter = new Post_Views_Counter_Counter();
119
  self::$instance->crawler_detect = new Post_Views_Counter_Crawler_Detect();
@@ -195,6 +196,7 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
195
  // actions
196
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
197
  add_action( 'wp_loaded', array( $this, 'load_pluggable_functions' ), 10 );
 
198
 
199
  // filters
200
  add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
@@ -328,9 +330,8 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
328
  * @param bool $forced
329
  */
330
  public function schedule_cache_flush( $forced = true ) {
331
- if ( $forced || ! wp_next_scheduled( 'pvc_flush_cached_counts' ) ) {
332
  wp_schedule_event( time(), 'post_views_counter_flush_interval', 'pvc_flush_cached_counts' );
333
- }
334
  }
335
 
336
  /**
@@ -355,6 +356,15 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
355
  include_once( POST_VIEWS_COUNTER_PATH . 'includes/functions.php' );
356
  }
357
 
 
 
 
 
 
 
 
 
 
358
  /**
359
  * Enqueue admin scripts and styles.
360
  *
@@ -362,25 +372,14 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
362
  * @param string $page
363
  */
364
  public function admin_enqueue_scripts( $page ) {
365
- wp_register_style(
366
- 'pvc-admin', POST_VIEWS_COUNTER_URL . '/css/admin.css'
367
- );
368
-
369
- wp_register_script(
370
- 'pvc-admin-settings', POST_VIEWS_COUNTER_URL . '/js/admin-settings.js', array( 'jquery' ), $this->defaults['version']
371
- );
372
-
373
- wp_register_script(
374
- 'pvc-admin-post', POST_VIEWS_COUNTER_URL . '/js/admin-post.js', array( 'jquery' ), $this->defaults['version']
375
- );
376
 
377
- wp_register_script(
378
- 'pvc-admin-quick-edit', POST_VIEWS_COUNTER_URL . '/js/admin-quick-edit.js', array( 'jquery', 'inline-edit-post' ), $this->defaults['version']
379
- );
380
 
381
  // load on PVC settings page
382
  if ( $page === 'settings_page_post-views-counter' ) {
383
-
384
  wp_enqueue_script( 'pvc-admin-settings' );
385
 
386
  wp_localize_script(
@@ -394,7 +393,6 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
394
 
395
  // load on single post page
396
  } elseif ( $page === 'post.php' || $page === 'post-new.php' ) {
397
-
398
  $post_types = Post_Views_Counter()->options['general']['post_types_count'];
399
 
400
  global $post_type;
@@ -419,7 +417,7 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
419
  wp_enqueue_script( 'pvc-admin-quick-edit' );
420
  }
421
  }
422
-
423
  /**
424
  * Add links to plugin support forum.
425
  *
@@ -428,7 +426,6 @@ if ( ! class_exists( 'Post_Views_Counter' ) ) :
428
  * @return array
429
  */
430
  public function plugin_row_meta( $links, $file ) {
431
-
432
  if ( ! current_user_can( 'install_plugins' ) )
433
  return $links;
434
 
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.14
6
  Author: dFactory
7
  Author URI: http://www.dfactory.eu/
8
  Plugin URI: http://www.dfactory.eu/plugins/post-views-counter/
23
 
24
  // exit if accessed directly
25
  if ( ! defined( 'ABSPATH' ) )
26
+ exit;
27
 
28
  if ( ! class_exists( 'Post_Views_Counter' ) ) :
29
 
31
  * Post Views Counter final class.
32
  *
33
  * @class Post_Views_Counter
34
+ * @version 1.2.14
35
  */
36
  final class Post_Views_Counter {
37
 
81
  'link_to_post' => true,
82
  'icon_class' => 'dashicons-chart-bar'
83
  ),
84
+ 'version' => '1.2.14'
85
  );
86
 
87
  /**
114
  if ( defined( 'SHORTINIT' ) && SHORTINIT ) {
115
  include_once( POST_VIEWS_COUNTER_PATH . 'includes/counter.php' );
116
  include_once( POST_VIEWS_COUNTER_PATH . 'includes/crawler-detect.php' );
117
+ include_once( POST_VIEWS_COUNTER_PATH . 'includes/functions.php' );
118
 
119
  self::$instance->counter = new Post_Views_Counter_Counter();
120
  self::$instance->crawler_detect = new Post_Views_Counter_Crawler_Detect();
196
  // actions
197
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
198
  add_action( 'wp_loaded', array( $this, 'load_pluggable_functions' ), 10 );
199
+ // add_action( 'init', array( $this, 'gutenberg_blocks' ) );
200
 
201
  // filters
202
  add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
330
  * @param bool $forced
331
  */
332
  public function schedule_cache_flush( $forced = true ) {
333
+ if ( $forced || ! wp_next_scheduled( 'pvc_flush_cached_counts' ) )
334
  wp_schedule_event( time(), 'post_views_counter_flush_interval', 'pvc_flush_cached_counts' );
 
335
  }
336
 
337
  /**
356
  include_once( POST_VIEWS_COUNTER_PATH . 'includes/functions.php' );
357
  }
358
 
359
+ /**
360
+ * Add Gutenberg blocks.
361
+ */
362
+ public function gutenberg_blocks() {
363
+ wp_register_script( 'pvc-admin-block-views', POST_VIEWS_COUNTER_URL . '/js/admin-block.js', array( 'wp-blocks', 'wp-element', 'wp-i18n' ) );
364
+
365
+ register_block_type( 'post-views-counter/views', array( 'editor_script' => 'pvc-admin-block-views' ) );
366
+ }
367
+
368
  /**
369
  * Enqueue admin scripts and styles.
370
  *
372
  * @param string $page
373
  */
374
  public function admin_enqueue_scripts( $page ) {
375
+ wp_register_style( 'pvc-admin', POST_VIEWS_COUNTER_URL . '/css/admin.css' );
 
 
 
 
 
 
 
 
 
 
376
 
377
+ wp_register_script( 'pvc-admin-settings', POST_VIEWS_COUNTER_URL . '/js/admin-settings.js', array( 'jquery' ), $this->defaults['version'] );
378
+ wp_register_script( 'pvc-admin-post', POST_VIEWS_COUNTER_URL . '/js/admin-post.js', array( 'jquery' ), $this->defaults['version'] );
379
+ wp_register_script( 'pvc-admin-quick-edit', POST_VIEWS_COUNTER_URL . '/js/admin-quick-edit.js', array( 'jquery', 'inline-edit-post' ), $this->defaults['version'] );
380
 
381
  // load on PVC settings page
382
  if ( $page === 'settings_page_post-views-counter' ) {
 
383
  wp_enqueue_script( 'pvc-admin-settings' );
384
 
385
  wp_localize_script(
393
 
394
  // load on single post page
395
  } elseif ( $page === 'post.php' || $page === 'post-new.php' ) {
 
396
  $post_types = Post_Views_Counter()->options['general']['post_types_count'];
397
 
398
  global $post_type;
417
  wp_enqueue_script( 'pvc-admin-quick-edit' );
418
  }
419
  }
420
+
421
  /**
422
  * Add links to plugin support forum.
423
  *
426
  * @return array
427
  */
428
  public function plugin_row_meta( $links, $file ) {
 
429
  if ( ! current_user_can( 'install_plugins' ) )
430
  return $links;
431
 
readme.txt CHANGED
@@ -4,8 +4,8 @@ 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.13
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
11
 
@@ -62,6 +62,9 @@ No questions yet.
62
 
63
  == Changelog ==
64
 
 
 
 
65
  = 1.2.13 =
66
  * New: Experimental Fast AJAX counter method (10+ times faster)
67
 
@@ -180,5 +183,5 @@ Initial release
180
 
181
  == Upgrade Notice ==
182
 
183
- = 1.2.13 =
184
- * New: Experimental Fast AJAX counter method (10+ times faster)
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.8
8
+ Stable tag: 1.2.14
9
  License: MIT License
10
  License URI: http://opensource.org/licenses/MIT
11
 
62
 
63
  == Changelog ==
64
 
65
+ = 1.2.14 =
66
+ * Fix: Bulk edit post views count reset issue
67
+
68
  = 1.2.13 =
69
  * New: Experimental Fast AJAX counter method (10+ times faster)
70
 
183
 
184
  == Upgrade Notice ==
185
 
186
+ = 1.2.14 =
187
+ * Fix: Bulk edit post views count reset issue