Top 10 – Popular posts plugin for WordPress - Version 2.5.6

Version Description

  • Features:
    • Added new button under Tools to recreate the PRIMARY KEYs
Download this release

Release Info

Developer Ajay
Plugin Icon 128x128 Top 10 – Popular posts plugin for WordPress
Version 2.5.6
Comparing to
See all releases

Code changes from version 2.5.5 to 2.5.6

Files changed (3) hide show
  1. includes/admin/tools.php +41 -0
  2. readme.txt +11 -1
  3. top-10.php +1 -1
includes/admin/tools.php CHANGED
@@ -24,6 +24,12 @@ if ( ! defined( 'WPINC' ) ) {
24
  */
25
  function tptn_tools_page() {
26
 
 
 
 
 
 
 
27
  /* Truncate overall posts table */
28
  if ( ( isset( $_POST['tptn_trunc_all'] ) ) && ( check_admin_referer( 'tptn-tools-settings' ) ) ) {
29
  tptn_trunc_count( false );
@@ -77,6 +83,14 @@ function tptn_tools_page() {
77
  <?php esc_html_e( 'Clear the Top 10 cache. This will also be cleared automatically when you save the settings page.', 'top-10' ); ?>
78
  </p>
79
 
 
 
 
 
 
 
 
 
80
  <h2 style="padding-left:0px"><?php esc_html_e( 'Reset database', 'top-10' ); ?></h2>
81
  <p>
82
  <input name="tptn_trunc_all" type="submit" id="tptn_trunc_all" value="<?php esc_attr_e( 'Reset Popular Posts Network-wide', 'top-10' ); ?>" class="button button-secondary" style="color:#f00" onclick="if (!confirm('<?php esc_attr_e( 'Are you sure you want to reset the popular posts?', 'top-10' ); ?>')) return false;" />
@@ -198,3 +212,30 @@ function tptn_merge_blogids( $daily = false ) {
198
 
199
  $wpdb->query( "DELETE FROM $table_name WHERE blog_id = 0" ); // WPCS: unprepared SQL OK.
200
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  */
25
  function tptn_tools_page() {
26
 
27
+ /* Truncate overall posts table */
28
+ if ( ( isset( $_POST['tptn_recreate_primary_key'] ) ) && ( check_admin_referer( 'tptn-tools-settings' ) ) ) {
29
+ tptn_recreate_primary_key();
30
+ add_settings_error( 'tptn-notices', '', esc_html__( 'Primary Key has been recreated', 'top-10' ), 'error' );
31
+ }
32
+
33
  /* Truncate overall posts table */
34
  if ( ( isset( $_POST['tptn_trunc_all'] ) ) && ( check_admin_referer( 'tptn-tools-settings' ) ) ) {
35
  tptn_trunc_count( false );
83
  <?php esc_html_e( 'Clear the Top 10 cache. This will also be cleared automatically when you save the settings page.', 'top-10' ); ?>
84
  </p>
85
 
86
+ <h2 style="padding-left:0px"><?php esc_html_e( 'Recreate Primary Key', 'top-10' ); ?></h2>
87
+ <p>
88
+ <input name="tptn_recreate_primary_key" type="submit" id="tptn_recreate_primary_key" value="<?php esc_attr_e( 'Recreate Primary Key', 'top-10' ); ?>" class="button button-secondary" />
89
+ </p>
90
+ <p class="description">
91
+ <?php esc_html_e( 'Deletes and reinitializes the primary key in the database tables.', 'top-10' ); ?>
92
+ </p>
93
+
94
  <h2 style="padding-left:0px"><?php esc_html_e( 'Reset database', 'top-10' ); ?></h2>
95
  <p>
96
  <input name="tptn_trunc_all" type="submit" id="tptn_trunc_all" value="<?php esc_attr_e( 'Reset Popular Posts Network-wide', 'top-10' ); ?>" class="button button-secondary" style="color:#f00" onclick="if (!confirm('<?php esc_attr_e( 'Are you sure you want to reset the popular posts?', 'top-10' ); ?>')) return false;" />
212
 
213
  $wpdb->query( "DELETE FROM $table_name WHERE blog_id = 0" ); // WPCS: unprepared SQL OK.
214
  }
215
+
216
+ /**
217
+ * Function to delete and create the primary keys in the database table.
218
+ *
219
+ * @since 2.5.6
220
+ */
221
+ function tptn_recreate_primary_key() {
222
+ global $wpdb;
223
+
224
+ $table_name = $wpdb->base_prefix . 'top_ten';
225
+ $table_name_daily = $wpdb->base_prefix . 'top_ten_daily';
226
+
227
+ $wpdb->hide_errors();
228
+
229
+ if ( $wpdb->query( $wpdb->prepare( "SHOW INDEXES FROM {$table_name} WHERE Key_name = %s", 'PRIMARY' ) ) ) {
230
+ $wpdb->query( 'ALTER TABLE ' . $table_name . ' DROP PRIMARY KEY ' ); // WPCS: unprepared SQL OK.
231
+ }
232
+ if ( $wpdb->query( $wpdb->prepare( "SHOW INDEXES FROM {$table_name_daily} WHERE Key_name = %s", 'PRIMARY' ) ) ) {
233
+ $wpdb->query( 'ALTER TABLE ' . $table_name_daily . ' DROP PRIMARY KEY ' ); // WPCS: unprepared SQL OK.
234
+ }
235
+
236
+ $wpdb->query( 'ALTER TABLE ' . $table_name . ' ADD PRIMARY KEY(postnumber, blog_id) ' ); // WPCS: unprepared SQL OK.
237
+ $wpdb->query( 'ALTER TABLE ' . $table_name_daily . ' ADD PRIMARY KEY(postnumber, dp_date, blog_id) ' ); // WPCS: unprepared SQL OK.
238
+
239
+ $wpdb->show_errors();
240
+ }
241
+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: webberzone, Ajay
4
  Donate link: https://ajaydsouza.com/donate/
5
  Stable tag: trunk
6
  Requires at least: 4.1
7
- Tested up to: 5.0
8
  License: GPLv2 or later
9
 
10
  Track daily and total visits on your blog posts. Display the count as well as popular and trending posts.
@@ -35,6 +35,11 @@ Top 10 also has powerful API and is fully extendable with WordPress actions and
35
  * **Works with caching plugins** like WP-Super-Cache, W3 Total Cache or Quick Cache
36
  * **Extendable code**: Top 10 has tonnes of filters and actions that allow any developer to easily add features, edit outputs, etc.
37
 
 
 
 
 
 
38
  = Donations =
39
 
40
  I spend a significant amount of my free time maintaining, updating and more importantly supporting this plugin. If you have been using this plugin and find this useful, do consider making a donation. This helps me pay for my hosting and domains.
@@ -165,6 +170,11 @@ add_filter( 'manage_edit-projects_sortable_columns', 'tptn_column_register_sorta
165
 
166
  == Changelog ==
167
 
 
 
 
 
 
168
  = 2.5.5 =
169
 
170
  * Bug fixes:
4
  Donate link: https://ajaydsouza.com/donate/
5
  Stable tag: trunk
6
  Requires at least: 4.1
7
+ Tested up to: 4.9
8
  License: GPLv2 or later
9
 
10
  Track daily and total visits on your blog posts. Display the count as well as popular and trending posts.
35
  * **Works with caching plugins** like WP-Super-Cache, W3 Total Cache or Quick Cache
36
  * **Extendable code**: Top 10 has tonnes of filters and actions that allow any developer to easily add features, edit outputs, etc.
37
 
38
+ = GDPR =
39
+ Top 10 is GDPR compliant as it doesn't collect any personal data about your visitors when installed out of the box. You can see the data the plugin stores in the `wp_top_ten` and `wp_top_ten_daily` tables in the database. Note: the prefix `wp` might be different if you have changed it from the default.
40
+
41
+ YOU ARE RESPONSIBLE FOR ENSURING THAT ALL GDPR REQUIREMENTS ARE MET ON YOUR WEBSITE.
42
+
43
  = Donations =
44
 
45
  I spend a significant amount of my free time maintaining, updating and more importantly supporting this plugin. If you have been using this plugin and find this useful, do consider making a donation. This helps me pay for my hosting and domains.
170
 
171
  == Changelog ==
172
 
173
+ = 2.5.6 =
174
+
175
+ * Features:
176
+ * Added new button under Tools to recreate the PRIMARY KEYs
177
+
178
  = 2.5.5 =
179
 
180
  * Bug fixes:
top-10.php CHANGED
@@ -14,7 +14,7 @@
14
  * Plugin Name: Top 10
15
  * Plugin URI: https://webberzone.com/plugins/top-10/
16
  * Description: Count daily and total visits per post and display the most popular posts based on the number of views
17
- * Version: 2.5.5
18
  * Author: Ajay D'Souza
19
  * Author URI: https://webberzone.com
20
  * License: GPL-2.0+
14
  * Plugin Name: Top 10
15
  * Plugin URI: https://webberzone.com/plugins/top-10/
16
  * Description: Count daily and total visits per post and display the most popular posts based on the number of views
17
+ * Version: 2.5.6
18
  * Author: Ajay D'Souza
19
  * Author URI: https://webberzone.com
20
  * License: GPL-2.0+