Skip to content

Commit 507621d

Browse files
committed
Release new version 2.8.3
= 2.8.3 - 2024/05/10 = * This maintenance release has an edge case fix that means total views record is created again at 1 when a duplicate post ID exists in the database. * Tweak - Test for compatibility with WordPress 6.5.3 * Fix - Get correct total views instead create new record with value 1 when it has duplicate post ID from database (edge case).
1 parent 649ad99 commit 507621d

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

page-views-count.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
/*
33
Plugin Name: Page Views Count
44
Description: Show front end users all time views and views today on posts, pages, index pages and custom post types with the Page Views Count Plugin. Use the Page Views Count function to add page views to any content type or object created by your theme or plugins.
5-
Version: 2.8.2
5+
Version: 2.8.3
66
Requires at least: 6.0
7-
Tested up to: 6.4.1
7+
Tested up to: 6.5.3
88
Author: a3rev Software
99
Author URI: https://a3rev.com
1010
Text Domain: page-views-count
@@ -23,7 +23,7 @@
2323

2424
define( 'A3_PVC_KEY', 'a3_page_view_count' );
2525
define( 'A3_PVC_PREFIX', 'wp_pvc_' );
26-
define( 'A3_PVC_VERSION', '2.8.2' );
26+
define( 'A3_PVC_VERSION', '2.8.3' );
2727
define( 'A3_PVC_G_FONTS', false );
2828

2929
global $pvc_enable_ajax_load;

readme.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Contributors: a3rev, a3rev Software, nguyencongtuan
33
Tags: wordpress page view, page view count , post views, post view count, gutenberg
44
Requires at least: 6.0
5-
Tested up to: 6.4.1
6-
Stable tag: 2.8.2
5+
Tested up to: 6.5.3
6+
Stable tag: 2.8.3
77
License: GPLv3
88
License URI: http://www.gnu.org/licenses/gpl-3.0.html
99

@@ -102,6 +102,11 @@ The manual installation method involves down loading our plugin and uploading it
102102

103103
== Changelog ==
104104

105+
= 2.8.3 - 2024/05/10 =
106+
* This maintenance release has an edge case fix that means total views record is created again at 1 when a duplicate post ID exists in the database.
107+
* Tweak - Test for compatibility with WordPress 6.5.3
108+
* Fix - Get correct total views instead create new record with value 1 when it has duplicate post ID from database (edge case).
109+
105110
= 2.8.2 - 2023/11/23 =
106111
* This maintenance release has plugin framework updates for compatibility with PHP 8.1 onwards, plus compatibility with WordPress 6.4.1
107112
* Tweak - Test for compatibility with WordPress 6.4.1
@@ -580,6 +585,9 @@ The manual installation method involves down loading our plugin and uploading it
580585

581586
== Upgrade Notice ==
582587

588+
= 2.8.3 =
589+
This maintenance release has an edge case fix that means total views record is created again at 1 when a duplicate post ID exists in the database.
590+
583591
= 2.8.2 =
584592
This maintenance release has plugin framework updates for compatibility with PHP 8.1 onwards, plus compatibility with WordPress 6.4.1
585593

src/pvc_class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function pvc_fetch_posts_stats( $post_ids ) {
5555

5656
$sql = $wpdb->prepare( "SELECT t.postnum AS post_id, t.postcount AS total, d.postcount AS today FROM ". $wpdb->prefix . "pvc_total AS t
5757
LEFT JOIN ". $wpdb->prefix . "pvc_daily AS d ON t.postnum = d.postnum
58-
WHERE t.postnum IN ( ".implode( ',', $post_ids )." ) AND d.time = %s", $nowisnow );
58+
WHERE t.postnum IN ( ".implode( ',', $post_ids )." ) AND d.time = %s ORDER BY t.postcount ASC", $nowisnow );
5959

6060
return $wpdb->get_results($sql);
6161
}
@@ -83,7 +83,7 @@ public static function pvc_fetch_post_total( $post_id ) {
8383
global $wpdb;
8484

8585
$sql = $wpdb->prepare( "SELECT postcount AS total FROM ". $wpdb->prefix . "pvc_total
86-
WHERE postnum = %s", $post_id );
86+
WHERE postnum = %s ORDER BY postcount DESC", $post_id );
8787
return $wpdb->get_var($sql);
8888
}
8989

@@ -103,14 +103,14 @@ public static function pvc_stats_update($post_id) {
103103
$nowisnow = wp_date('Y-m-d');
104104

105105
// first try and update the existing total post counter
106-
$results = $wpdb->query( $wpdb->prepare( "UPDATE ". $wpdb->prefix . "pvc_total SET postcount = postcount+1 WHERE postnum = '%s' LIMIT 1", $post_id ) );
106+
$results = $wpdb->query( $wpdb->prepare( "UPDATE ". $wpdb->prefix . "pvc_total SET postcount = postcount+1 WHERE postnum = %s LIMIT 1", $post_id ) );
107107

108108
// error_log( json_encode( $results ) );
109109

110110
// if it doesn't exist, then insert two new records
111111
// one in the total views, another in today's views
112112
if ($results == 0) {
113-
$wpdb->query( $wpdb->prepare( "INSERT INTO ". $wpdb->prefix . "pvc_total (postnum, postcount) VALUES ('%s', 1)", $post_id ) );
113+
$wpdb->query( $wpdb->prepare( "INSERT INTO ". $wpdb->prefix . "pvc_total (postnum, postcount) VALUES ( %s, 1)", $post_id ) );
114114
$wpdb->query( $wpdb->prepare ( "INSERT INTO ". $wpdb->prefix . "pvc_daily (time, postnum, postcount) VALUES ('%s', '%s', 1)", $nowisnow, $post_id ) );
115115
// post exists so let's just update the counter
116116
} else {

0 commit comments

Comments
 (0)