Top 10 – Popular posts plugin for WordPress - Version 2.9.3

Version Description

Release post: https://webberzone.com/blog/top-10-v2-9-0/

  • Enhancements:

    • Cache now uses MD5 generated keys based on the Top 10 parameters being passed. This means the cache should now work with shortcodes and manual implementations
    • Database creation now uses the correct collation
  • Bug fixes:

    • include_cat_ids didn't work with the shortcode
    • Password protected posts will no longer show the excerpt
Download this release

Release Info

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

Code changes from version 2.9.2 to 2.9.3

includes/activate-deactivate.php CHANGED
@@ -50,7 +50,9 @@ register_activation_hook( TOP_TEN_PLUGIN_FILE, 'tptn_activation_hook' );
50
  function tptn_single_activate() {
51
  global $wpdb, $tptn_db_version;
52
 
53
- $tptn_settings = tptn_get_settings();
 
 
54
 
55
  $table_name = $wpdb->base_prefix . 'top_ten';
56
  $table_name_daily = $wpdb->base_prefix . 'top_ten_daily';
@@ -63,9 +65,8 @@ function tptn_single_activate() {
63
  cntaccess bigint(20) NOT NULL,
64
  blog_id bigint(20) NOT NULL DEFAULT '1',
65
  PRIMARY KEY (postnumber, blog_id)
66
- );";
67
 
68
- require_once ABSPATH . 'wp-admin/includes/upgrade.php';
69
  dbDelta( $sql );
70
 
71
  }
@@ -79,9 +80,8 @@ function tptn_single_activate() {
79
  dp_date DATETIME NOT NULL,
80
  blog_id bigint(20) NOT NULL DEFAULT '1',
81
  PRIMARY KEY (postnumber, dp_date, blog_id)
82
- );";
83
 
84
- require_once ABSPATH . 'wp-admin/includes/upgrade.php';
85
  dbDelta( $sql );
86
 
87
  }
@@ -103,7 +103,7 @@ function tptn_single_activate() {
103
  cntaccess bigint(20) NOT NULL,
104
  blog_id bigint(20) NOT NULL DEFAULT '1',
105
  PRIMARY KEY (postnumber, blog_id)
106
- );";
107
 
108
  $sql .= 'CREATE TABLE ' . $table_name_daily . " (
109
  postnumber bigint(20) NOT NULL,
@@ -111,9 +111,8 @@ function tptn_single_activate() {
111
  dp_date DATETIME NOT NULL,
112
  blog_id bigint(20) NOT NULL DEFAULT '1',
113
  PRIMARY KEY (postnumber, dp_date, blog_id)
114
- );";
115
 
116
- require_once ABSPATH . 'wp-admin/includes/upgrade.php';
117
  dbDelta( $sql );
118
 
119
  update_site_option( 'tptn_db_version', $tptn_db_version );
50
  function tptn_single_activate() {
51
  global $wpdb, $tptn_db_version;
52
 
53
+ $tptn_settings = tptn_get_settings();
54
+ $charset_collate = $wpdb->get_charset_collate();
55
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
56
 
57
  $table_name = $wpdb->base_prefix . 'top_ten';
58
  $table_name_daily = $wpdb->base_prefix . 'top_ten_daily';
65
  cntaccess bigint(20) NOT NULL,
66
  blog_id bigint(20) NOT NULL DEFAULT '1',
67
  PRIMARY KEY (postnumber, blog_id)
68
+ ) $charset_collate;";
69
 
 
70
  dbDelta( $sql );
71
 
72
  }
80
  dp_date DATETIME NOT NULL,
81
  blog_id bigint(20) NOT NULL DEFAULT '1',
82
  PRIMARY KEY (postnumber, dp_date, blog_id)
83
+ ) $charset_collate;";
84
 
 
85
  dbDelta( $sql );
86
 
87
  }
103
  cntaccess bigint(20) NOT NULL,
104
  blog_id bigint(20) NOT NULL DEFAULT '1',
105
  PRIMARY KEY (postnumber, blog_id)
106
+ ) $charset_collate;";
107
 
108
  $sql .= 'CREATE TABLE ' . $table_name_daily . " (
109
  postnumber bigint(20) NOT NULL,
111
  dp_date DATETIME NOT NULL,
112
  blog_id bigint(20) NOT NULL DEFAULT '1',
113
  PRIMARY KEY (postnumber, dp_date, blog_id)
114
+ ) $charset_collate;";
115
 
 
116
  dbDelta( $sql );
117
 
118
  update_site_option( 'tptn_db_version', $tptn_db_version );
includes/admin/cache.php CHANGED
@@ -12,13 +12,14 @@
12
  */
13
  function tptn_ajax_clearcache() {
14
 
15
- tptn_cache_delete();
16
 
17
  exit(
18
  wp_json_encode(
19
  array(
20
  'success' => 1,
21
- 'message' => __( 'Top 10 cache has been cleared', 'top-10' ),
 
22
  )
23
  )
24
  );
@@ -60,9 +61,13 @@ function tptn_cache_get_keys() {
60
  /**
61
  * Delete the Top 10 cache.
62
  *
63
- * @param array $transients Array of transients to delete.
 
 
 
64
  */
65
  function tptn_cache_delete( $transients = array() ) {
 
66
 
67
  $default_transients = tptn_cache_get_keys();
68
 
@@ -73,8 +78,12 @@ function tptn_cache_delete( $transients = array() ) {
73
  }
74
 
75
  foreach ( $transients as $transient ) {
76
- delete_transient( $transient );
 
 
 
77
  }
 
78
  }
79
 
80
 
@@ -93,7 +102,7 @@ function tptn_cache_get_widget_keys() {
93
  $sql = "
94
  SELECT option_name
95
  FROM {$wpdb->options}
96
- WHERE `option_name` LIKE '_transient_tptn_%_widget%'
97
  ";
98
 
99
  $results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
12
  */
13
  function tptn_ajax_clearcache() {
14
 
15
+ $count = tptn_cache_delete();
16
 
17
  exit(
18
  wp_json_encode(
19
  array(
20
  'success' => 1,
21
+ /* translators: 1: Number of entries. */
22
+ 'message' => sprintf( _n( '%s entry cleared', '%s entries cleared', $count, 'text-domain' ), number_format_i18n( $count ) ),
23
  )
24
  )
25
  );
61
  /**
62
  * Delete the Top 10 cache.
63
  *
64
+ * @since 2.3.0
65
+ *
66
+ * @param array $transients Array of transients to delete.
67
+ * @return int Number of transients deleted.
68
  */
69
  function tptn_cache_delete( $transients = array() ) {
70
+ $loop = 0;
71
 
72
  $default_transients = tptn_cache_get_keys();
73
 
78
  }
79
 
80
  foreach ( $transients as $transient ) {
81
+ $del = delete_transient( $transient );
82
+ if ( $del ) {
83
+ $loop++;
84
+ }
85
  }
86
+ return $loop;
87
  }
88
 
89
 
102
  $sql = "
103
  SELECT option_name
104
  FROM {$wpdb->options}
105
+ WHERE `option_name` LIKE '_transient_tptn_%'
106
  ";
107
 
108
  $results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
includes/formatting.php CHANGED
@@ -17,12 +17,15 @@
17
  function tptn_excerpt( $id, $excerpt_length = 0, $use_excerpt = true ) {
18
  $content = '';
19
 
 
 
 
 
20
  if ( $use_excerpt ) {
21
- $content = get_post( $id )->post_excerpt;
22
  }
23
-
24
- if ( '' === $content ) {
25
- $content = get_post( $id )->post_content;
26
  }
27
 
28
  $output = wp_strip_all_tags( strip_shortcodes( $content ) );
@@ -31,6 +34,10 @@ function tptn_excerpt( $id, $excerpt_length = 0, $use_excerpt = true ) {
31
  $output = wp_trim_words( $output, $excerpt_length );
32
  }
33
 
 
 
 
 
34
  /**
35
  * Filters excerpt generated by tptn.
36
  *
17
  function tptn_excerpt( $id, $excerpt_length = 0, $use_excerpt = true ) {
18
  $content = '';
19
 
20
+ $post = get_post( $id );
21
+ if ( empty( $post ) ) {
22
+ return '';
23
+ }
24
  if ( $use_excerpt ) {
25
+ $content = $post->post_excerpt;
26
  }
27
+ if ( empty( $content ) ) {
28
+ $content = $post->post_content;
 
29
  }
30
 
31
  $output = wp_strip_all_tags( strip_shortcodes( $content ) );
34
  $output = wp_trim_words( $output, $excerpt_length );
35
  }
36
 
37
+ if ( post_password_required( $post ) ) {
38
+ $output = __( 'There is no excerpt because this is a protected post.', 'top-10' );
39
+ }
40
+
41
  /**
42
  * Filters excerpt generated by tptn.
43
  *
includes/modules/shortcode.php CHANGED
@@ -20,10 +20,11 @@ function tptn_shortcode( $atts, $content = null ) {
20
  array_merge(
21
  $tptn_settings,
22
  array(
23
- 'heading' => 1,
24
- 'daily' => 0,
25
- 'is_shortcode' => 1,
26
- 'offset' => 0,
 
27
  )
28
  ),
29
  $atts,
20
  array_merge(
21
  $tptn_settings,
22
  array(
23
+ 'heading' => 1,
24
+ 'daily' => 0,
25
+ 'is_shortcode' => 1,
26
+ 'offset' => 0,
27
+ 'include_cat_ids' => '',
28
  )
29
  ),
30
  $atts,
includes/public/display-posts.php CHANGED
@@ -60,11 +60,7 @@ function tptn_pop_posts( $args ) {
60
 
61
  // Check if the cache is enabled and if the output exists. If so, return the output.
62
  if ( $args['cache'] && ! $args['posts_only'] ) {
63
- $cache_name = 'tptn';
64
- $cache_name .= $args['daily'] ? '_daily' : '_total';
65
- $cache_name .= $args['is_widget'] ? '_widget' . $args['instance_id'] : '';
66
- $cache_name .= $args['is_shortcode'] ? '_shortcode' : '';
67
- $cache_name .= $args['is_manual'] ? '_manual' : '';
68
 
69
  $output = get_transient( $cache_name );
70
 
@@ -574,3 +570,19 @@ function tptn_pop_posts_feed_callback( $daily = false ) {
574
  }
575
 
576
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  // Check if the cache is enabled and if the output exists. If so, return the output.
62
  if ( $args['cache'] && ! $args['posts_only'] ) {
63
+ $cache_name = tptn_cache_get_key( $args );
 
 
 
 
64
 
65
  $output = get_transient( $cache_name );
66
 
570
  }
571
 
572
  }
573
+
574
+
575
+ /**
576
+ * Get the key based on a list of parameters.
577
+ *
578
+ * @since 2.9.3
579
+ *
580
+ * @param array $attr Array of attributes.
581
+ * @return string Cache key
582
+ */
583
+ function tptn_cache_get_key( $attr ) {
584
+
585
+ $key = 'tptn_cache_' . md5( wp_json_encode( $attr ) );
586
+
587
+ return $key;
588
+ }
languages/top-10-en_US.po CHANGED
@@ -2,7 +2,7 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Top 10\n"
4
  "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2020-04-20 18:40+0100\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Ajay D'Souza <me@ajaydsouza.com>\n"
8
  "Language-Team: WebberZone <plugins@webberzone.com>\n"
@@ -166,10 +166,6 @@ msgstr ""
166
  msgid "Top 10 - Network Popular Posts"
167
  msgstr ""
168
 
169
- #: includes/admin/cache.php:21
170
- msgid "Top 10 cache has been cleared"
171
- msgstr ""
172
-
173
  #: includes/admin/class-top-ten-network-statistics-table.php:36
174
  #: includes/admin/class-top-ten-statistics-table.php:43
175
  msgid "popular_post"
@@ -1491,6 +1487,10 @@ msgstr ""
1491
  msgid "<h3>Daily Popular</h3>"
1492
  msgstr ""
1493
 
 
 
 
 
1494
  #: includes/modules/class-top-ten-count-widget.php:30
1495
  msgid "Overall count [Top 10]"
1496
  msgstr ""
@@ -1575,13 +1575,13 @@ msgstr ""
1575
  msgid "Post types to include:"
1576
  msgstr ""
1577
 
1578
- #: includes/public/display-posts.php:92
1579
  msgid ""
1580
  "posts_only argument has been deprecated. Use get_tptn_pop_posts() to get the "
1581
  "posts only."
1582
  msgstr ""
1583
 
1584
- #: includes/public/display-posts.php:219
1585
  #, php-format
1586
  msgid ""
1587
  "Popular posts by <a href=\"%1$s\" rel=\"nofollow\" %2$s>Top 10 plugin</a>"
2
  msgstr ""
3
  "Project-Id-Version: Top 10\n"
4
  "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2020-05-07 22:00+0100\n"
6
  "PO-Revision-Date: \n"
7
  "Last-Translator: Ajay D'Souza <me@ajaydsouza.com>\n"
8
  "Language-Team: WebberZone <plugins@webberzone.com>\n"
166
  msgid "Top 10 - Network Popular Posts"
167
  msgstr ""
168
 
 
 
 
 
169
  #: includes/admin/class-top-ten-network-statistics-table.php:36
170
  #: includes/admin/class-top-ten-statistics-table.php:43
171
  msgid "popular_post"
1487
  msgid "<h3>Daily Popular</h3>"
1488
  msgstr ""
1489
 
1490
+ #: includes/formatting.php:38
1491
+ msgid "There is no excerpt because this is a protected post."
1492
+ msgstr ""
1493
+
1494
  #: includes/modules/class-top-ten-count-widget.php:30
1495
  msgid "Overall count [Top 10]"
1496
  msgstr ""
1575
  msgid "Post types to include:"
1576
  msgstr ""
1577
 
1578
+ #: includes/public/display-posts.php:88
1579
  msgid ""
1580
  "posts_only argument has been deprecated. Use get_tptn_pop_posts() to get the "
1581
  "posts only."
1582
  msgstr ""
1583
 
1584
+ #: includes/public/display-posts.php:215
1585
  #, php-format
1586
  msgid ""
1587
  "Popular posts by <a href=\"%1$s\" rel=\"nofollow\" %2$s>Top 10 plugin</a>"
languages/top-10-en_US.pot CHANGED
@@ -3,7 +3,7 @@ msgid ""
3
  msgstr ""
4
  "Project-Id-Version: Top 10\n"
5
  "Report-Msgid-Bugs-To: \n"
6
- "POT-Creation-Date: 2020-04-20 18:40+0100\n"
7
  "PO-Revision-Date: \n"
8
  "Last-Translator: Ajay D'Souza <me@ajaydsouza.com>\n"
9
  "Language-Team: WebberZone <plugins@webberzone.com>\n"
@@ -167,10 +167,6 @@ msgstr ""
167
  msgid "Top 10 - Network Popular Posts"
168
  msgstr ""
169
 
170
- #: includes/admin/cache.php:21
171
- msgid "Top 10 cache has been cleared"
172
- msgstr ""
173
-
174
  #: includes/admin/class-top-ten-network-statistics-table.php:36
175
  #: includes/admin/class-top-ten-statistics-table.php:43
176
  msgid "popular_post"
@@ -1492,6 +1488,10 @@ msgstr ""
1492
  msgid "<h3>Daily Popular</h3>"
1493
  msgstr ""
1494
 
 
 
 
 
1495
  #: includes/modules/class-top-ten-count-widget.php:30
1496
  msgid "Overall count [Top 10]"
1497
  msgstr ""
@@ -1576,13 +1576,13 @@ msgstr ""
1576
  msgid "Post types to include:"
1577
  msgstr ""
1578
 
1579
- #: includes/public/display-posts.php:92
1580
  msgid ""
1581
  "posts_only argument has been deprecated. Use get_tptn_pop_posts() to get the "
1582
  "posts only."
1583
  msgstr ""
1584
 
1585
- #: includes/public/display-posts.php:219
1586
  #, php-format
1587
  msgid ""
1588
  "Popular posts by <a href=\"%1$s\" rel=\"nofollow\" %2$s>Top 10 plugin</a>"
3
  msgstr ""
4
  "Project-Id-Version: Top 10\n"
5
  "Report-Msgid-Bugs-To: \n"
6
+ "POT-Creation-Date: 2020-05-07 22:00+0100\n"
7
  "PO-Revision-Date: \n"
8
  "Last-Translator: Ajay D'Souza <me@ajaydsouza.com>\n"
9
  "Language-Team: WebberZone <plugins@webberzone.com>\n"
167
  msgid "Top 10 - Network Popular Posts"
168
  msgstr ""
169
 
 
 
 
 
170
  #: includes/admin/class-top-ten-network-statistics-table.php:36
171
  #: includes/admin/class-top-ten-statistics-table.php:43
172
  msgid "popular_post"
1488
  msgid "<h3>Daily Popular</h3>"
1489
  msgstr ""
1490
 
1491
+ #: includes/formatting.php:38
1492
+ msgid "There is no excerpt because this is a protected post."
1493
+ msgstr ""
1494
+
1495
  #: includes/modules/class-top-ten-count-widget.php:30
1496
  msgid "Overall count [Top 10]"
1497
  msgstr ""
1576
  msgid "Post types to include:"
1577
  msgstr ""
1578
 
1579
+ #: includes/public/display-posts.php:88
1580
  msgid ""
1581
  "posts_only argument has been deprecated. Use get_tptn_pop_posts() to get the "
1582
  "posts only."
1583
  msgstr ""
1584
 
1585
+ #: includes/public/display-posts.php:215
1586
  #, php-format
1587
  msgid ""
1588
  "Popular posts by <a href=\"%1$s\" rel=\"nofollow\" %2$s>Top 10 plugin</a>"
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Tags: popular posts, top 10, counter, top posts, daily popular, page views, statistics, tracker
3
  Contributors: webberzone, Ajay
4
  Donate link: https://ajaydsouza.com/donate/
5
- Stable tag: 2.9.2
6
  Requires at least: 4.9
7
  Tested up to: 5.4
8
  License: GPLv2 or later
@@ -160,6 +160,18 @@ add_filter( 'manage_edit-projects_sortable_columns', 'tptn_column_register_sorta
160
 
161
  == Changelog ==
162
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  = 2.9.2 =
164
 
165
  Release post: [https://webberzone.com/blog/top-10-v2-9-0/](https://webberzone.com/blog/top-10-v2-9-0/)
@@ -221,7 +233,6 @@ For previous changelog entries, please refer to the separate changelog.txt file
221
 
222
  == Upgrade Notice ==
223
 
224
- = 2.9.2 =
225
- Bug fixes and new features;
226
- Check the Changelog for more details
227
 
2
  Tags: popular posts, top 10, counter, top posts, daily popular, page views, statistics, tracker
3
  Contributors: webberzone, Ajay
4
  Donate link: https://ajaydsouza.com/donate/
5
+ Stable tag: 2.9.3
6
  Requires at least: 4.9
7
  Tested up to: 5.4
8
  License: GPLv2 or later
160
 
161
  == Changelog ==
162
 
163
+ = 2.9.3 =
164
+
165
+ Release post: [https://webberzone.com/blog/top-10-v2-9-0/](https://webberzone.com/blog/top-10-v2-9-0/)
166
+
167
+ * Enhancements:
168
+ * Cache now uses MD5 generated keys based on the Top 10 parameters being passed. This means the cache should now work with shortcodes and manual implementations
169
+ * Database creation now uses the correct collation
170
+
171
+ * Bug fixes:
172
+ * `include_cat_ids` didn't work with the shortcode
173
+ * Password protected posts will no longer show the excerpt
174
+
175
  = 2.9.2 =
176
 
177
  Release post: [https://webberzone.com/blog/top-10-v2-9-0/](https://webberzone.com/blog/top-10-v2-9-0/)
233
 
234
  == Upgrade Notice ==
235
 
236
+ = 2.9.3 =
237
+ Bug fixes and new features; Check the Changelog for more details or the release posts on https://webberzone.com
 
238
 
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.9.2
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.9.3
18
  * Author: Ajay D'Souza
19
  * Author URI: https://webberzone.com
20
  * License: GPL-2.0+