Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/wp-stats/stats-options.php
+++ b/wp-stats/stats-options.php
@@ -8,11 +8,18 @@
check_admin_referer( 'wp-stats_options' );
$stats_url = ! empty( $_POST['stats_url'] ) ? esc_url_raw( $_POST['stats_url'] ) : '';
$stats_mostlimit = ! empty( $_POST['stats_mostlimit'] ) ? (int) trim( $_POST['stats_mostlimit'] ) : 10;
- $stats_display = ! empty( $_POST['stats_display'] ) ? $_POST['stats_display'] : array();
- $stats_display_array = array();
- if ( ! empty( $stats_display ) ) {
- foreach ( $stats_display as $stat_display ) {
- $stat_display = addslashes( $stat_display );
+ $stats_display = ! empty( $_POST['stats_display'] ) ? (array) $_POST['stats_display'] : array();
+ // Only checked boxes are posted, so start every known option at 0 and switch
+ // on the ones that came back, keeping unchecked options stored as 0.
+ $stats_display_stored = get_option( 'stats_display' );
+ $stats_display_stored = is_array( $stats_display_stored ) ? $stats_display_stored : array();
+ $stats_display_array = array_fill_keys(
+ array_keys( array_merge( stats_display_defaults(), $stats_display_stored ) ),
+ 0
+ );
+ foreach ( $stats_display as $stat_display ) {
+ $stat_display = sanitize_key( $stat_display );
+ if ( '' !== $stat_display ) {
$stats_display_array[ $stat_display ] = 1;
}
}
@@ -40,16 +47,13 @@
$stats_mostlimit = (int) get_option( 'stats_mostlimit' );
$stats_display = get_option( 'stats_display' );
-$stats_display['total_stats'] = isset( $stats_display['total_stats'] ) ? (int) $stats_display['total_stats'] : 0;
-$stats_display['recent_posts'] = isset( $stats_display['recent_posts'] ) ? (int) $stats_display['recent_posts'] : 0;
-$stats_display['recent_comments'] = isset( $stats_display['recent_comments'] ) ? (int) $stats_display['recent_comments'] : 0;
-$stats_display['commented_post'] = isset( $stats_display['commented_post'] ) ? (int) $stats_display['commented_post'] : 0;
-$stats_display['commented_page'] = isset( $stats_display['commented_page'] ) ? (int) $stats_display['commented_page'] : 0;
-$stats_display['authors'] = isset( $stats_display['authors'] ) ? (int) $stats_display['authors'] : 0;
-$stats_display['comment_members'] = isset( $stats_display['comment_members'] ) ? (int) $stats_display['comment_members'] : 0;
-$stats_display['post_cats'] = isset( $stats_display['post_cats'] ) ? (int) $stats_display['post_cats'] : 0;
-$stats_display['link_cats'] = isset( $stats_display['link_cats'] ) ? (int) $stats_display['link_cats'] : 0;
-$stats_display['tags_list'] = isset( $stats_display['tags_list'] ) ? (int) $stats_display['tags_list'] : 0;
+$stats_display = array_map(
+ 'intval',
+ array_merge(
+ array_fill_keys( array_keys( stats_display_defaults() ), 0 ),
+ is_array( $stats_display ) ? $stats_display : array()
+ )
+);
$page_admin_general_stats = '';
$page_admin_plugins_stats = '';
--- a/wp-stats/wp-stats.php
+++ b/wp-stats/wp-stats.php
@@ -3,7 +3,7 @@
Plugin Name: WP-Stats
Plugin URI: https://lesterchan.net/portfolio/programming/php/
Description: Display your WordPress blog statistics. Ranging from general total statistics, some of my plugins statistics and top 10 statistics.
-Version: 2.56
+Version: 2.56.1
Author: Lester 'GaMerZ' Chan
Author URI: https://lesterchan.net
Text Domain: wp-stats
@@ -11,7 +11,7 @@
/*
- Copyright 2020 Lester Chan (email : lesterchan@gmail.com)
+ Copyright 2026 Lester Chan (email : lesterchan@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -153,7 +153,7 @@
$post_title = get_the_title();
$post_date = get_the_time(sprintf(__('%s @ %s', 'wp-stats'), get_option('date_format'), get_option('time_format')));
$display_name = stripslashes($post->display_name);
- $temp .= "<li>$post_date - <a href="".get_permalink()."" title="".sprintf(__('View post %s', 'wp-stats'), $post_title)."">$post_title</a> ($display_name)</li>n";
+ $temp .= "<li>$post_date - <a href="".esc_url(get_permalink())."" title="".esc_attr(sprintf(__('View post %s', 'wp-stats'), $post_title))."">".esc_html($post_title)."</a> (".esc_html($display_name).")</li>n";
}
} else {
$temp = '<li>'.__('N/A', 'wp-stats').'</li>';
@@ -181,7 +181,7 @@
$post_title = get_the_title();
$comment_author = htmlspecialchars(stripslashes($post->comment_author));
$comment_date = mysql2date(sprintf(__('%s @ %s', 'wp-stats'), get_option('date_format'), get_option('time_format')), $post->comment_date);
- $temp .= "<li>$comment_date - $comment_author (<a href="".get_permalink()."#comment-".$post->comment_ID."" title="".sprintf(__('View comments in post %s', 'wp-stats'), $post_title)."">$post_title</a>)</li>n";
+ $temp .= "<li>$comment_date - $comment_author (<a href="".esc_url(get_permalink()."#comment-".$post->comment_ID)."" title="".esc_attr(sprintf(__('View comments in post %s', 'wp-stats'), $post_title))."">".esc_html($post_title)."</a>)</li>n";
}
} else {
$temp = '<li>'.__('N/A', 'wp-stats').'</li>';
@@ -209,13 +209,13 @@
foreach ($mostcommenteds as $post) {
$post_title = get_the_title();
$comment_total = $post->comment_total;
- $temp .= "<li><a href="".get_permalink()."" title="".sprintf(__('View comments in post %s', 'wp-stats'), $post_title)."">".snippet_text($post_title, $chars)."</a> - ".sprintf(_n('%s comment', '%s comments', $comment_total, 'wp-stats'), number_format_i18n($comment_total))."</li>";
+ $temp .= "<li><a href="".esc_url(get_permalink())."" title="".esc_attr(sprintf(__('View comments in post %s', 'wp-stats'), $post_title))."">".esc_html(snippet_text($post_title, $chars))."</a> - ".sprintf(_n('%s comment', '%s comments', $comment_total, 'wp-stats'), number_format_i18n($comment_total))."</li>";
}
} else {
foreach ($mostcommenteds as $post) {
$post_title = get_the_title();
$comment_total = $post->comment_total;
- $temp .= "<li><a href="".get_permalink()."" title="".sprintf(__('View comments in post %s', 'wp-stats'), $post_title)."">$post_title</a> - ".sprintf(_n('%s comment', '%s comments', $comment_total, 'wp-stats'), number_format_i18n($comment_total))."</li>";
+ $temp .= "<li><a href="".esc_url(get_permalink())."" title="".esc_attr(sprintf(__('View comments in post %s', 'wp-stats'), $post_title))."">".esc_html($post_title)."</a> - ".sprintf(_n('%s comment', '%s comments', $comment_total, 'wp-stats'), number_format_i18n($comment_total))."</li>";
}
}
} else {
@@ -248,9 +248,9 @@
$display_name = strip_tags(stripslashes($post->display_name));
$posts_total = number_format_i18n($post->posts_total);
if($using_permalink) {
- $temp .= "<li><a href="".get_option('home').$author_link."" title="".sprintf(__('View posts posted by %s', 'wp-stats'), $display_name)."">$display_name</a> ($posts_total)</li>n";
+ $temp .= "<li><a href="".esc_url(get_option('home').$author_link)."" title="".esc_attr(sprintf(__('View posts posted by %s', 'wp-stats'), $display_name))."">".esc_html($display_name)."</a> ($posts_total)</li>n";
} else {
- $temp .= "<li><a href="".get_option('siteurl')."/?author_name=$post_author" title="".sprintf(__('View posts posted by %s', 'wp-stats'), $display_name)."">$display_name</a> ($posts_total)</li>n";
+ $temp .= "<li><a href="".esc_url(get_option('siteurl')."/?author_name=".$post_author)."" title="".esc_attr(sprintf(__('View posts posted by %s', 'wp-stats'), $display_name))."">".esc_html($display_name)."</a> ($posts_total)</li>n";
}
}
} else {
@@ -282,7 +282,7 @@
if($comment_total >= $threshhold) {
$comment_author = strip_tags(stripslashes($comment->comment_author));
$comment_author_link = urlencode($comment_author);
- $temp .= "<li><a href="".stats_page_link($comment_author_link)."" title="".sprintf(__('View all comments posted by %s', 'wp-stats'), $comment_author)."">$comment_author</a> (".number_format_i18n($comment_total).")</li>n";
+ $temp .= "<li><a href="".stats_page_link($comment_author_link)."" title="".esc_attr(sprintf(__('View all comments posted by %s', 'wp-stats'), $comment_author))."">".esc_html($comment_author)."</a> (".number_format_i18n($comment_total).")</li>n";
}
}
} else {
@@ -376,7 +376,7 @@
function stats_page() {
global $wpdb, $post;
// Variables Variables Variables
- $comment_author = isset( $_GET['stats_author'] ) ? urldecode(strip_tags(stripslashes(trim($_GET['stats_author'])))) : '';
+ $comment_author = isset( $_GET['stats_author'] ) ? sanitize_text_field( wp_unslash( $_GET['stats_author'] ) ) : '';
$page = isset( $_GET['stats_page'] ) ? (int) $_GET['stats_page'] : 1;
$temp_stats = '';
$temp_post = $post;
@@ -386,7 +386,7 @@
// Default wp-stats.php Page
if(empty($comment_author)) {
// General Stats
- if($stats_display['total_stats'] === 1) {
+ if((int) ($stats_display['total_stats'] ?? 0) === 1) {
$temp_stats .= '<h2 id="GeneralStats">'.__('General Stats', 'wp-stats').'</h2>'."n";
$temp_stats .= '<p><strong>'.__('Total Stats', 'wp-stats').'</strong></p>'."n";
$temp_stats .= '<ul>'."n";
@@ -420,7 +420,7 @@
$temp_stats .= '<h2 id="TopRecentStats">'.sprintf(_n('Top %s Recent Stat', 'Top %s Recent Stats', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</h2>'."n";
// Recent Posts
- if($stats_display['recent_posts'] === 1) {
+ if((int) ($stats_display['recent_posts'] ?? 0) === 1) {
$temp_stats .= '<p><strong>'.sprintf(_n('%s Recent Post', '%s Recent Posts', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</strong></p>'."n";
$temp_stats .= '<ul>'."n";
$temp_stats .= get_recentposts('post', $stats_mostlimit, false);
@@ -428,7 +428,7 @@
}
// Recent Comments
- if($stats_display['recent_comments'] === 1) {
+ if((int) ($stats_display['recent_comments'] ?? 0) === 1) {
$temp_stats .= '<p><strong>'.sprintf(_n('%s Recent Comment', '%s Recent Comments', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</strong></p>'."n";
$temp_stats .= '<ul>'."n";
$temp_stats .= get_recentcomments('both', $stats_mostlimit, false);
@@ -442,7 +442,7 @@
$temp_stats .= '<h2 id="TopMostHighestStats">'.sprintf(_n('%s Most/Highest Stat', '%s Most/Highest Stats', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</h2>'."n";
// Most Commented Posts
- if($stats_display['commented_post'] === 1) {
+ if((int) ($stats_display['commented_post'] ?? 0) === 1) {
$temp_stats .= '<p><strong>'.sprintf(_n('%s Most Commented Post', '%s Most Commented Posts', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</strong></p>'."n";
$temp_stats .= '<ul>'."n";
$temp_stats .= get_mostcommented('post', $stats_mostlimit, 0, false);
@@ -450,7 +450,7 @@
}
// Most Commented Pages
- if($stats_display['commented_page'] === 1) {
+ if((int) ($stats_display['commented_page'] ?? 0) === 1) {
$temp_stats .= '<p><strong>'.sprintf(_n('%s Most Commented Page', '%s Most Commented Pages', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</strong></p>'."n";
$temp_stats .= '<ul>'."n";
$temp_stats .= get_mostcommented('page', $stats_mostlimit, 0, false);
@@ -464,7 +464,7 @@
$temp_stats .= '<h2 id="AuthorsStats">'.__('Authors Stats', 'wp-stats').'</h2>'."n";
// Authors
- if($stats_display['authors'] === 1) {
+ if((int) ($stats_display['authors'] ?? 0) === 1) {
$temp_stats .= '<p><strong>'.__('Authors', 'wp-stats').'</strong></p>'."n";
$temp_stats .= '<ol>'."n";
$temp_stats .= get_authorsstats('post', false);
@@ -478,7 +478,7 @@
$temp_stats .= '<h2 id="CommentsMembersStats">'.__('Comments' Members Stats', 'wp-stats').'</h2>'."n";
// Comments' Member
- if($stats_display['comment_members'] === 1) {
+ if((int) ($stats_display['comment_members'] ?? 0) === 1) {
$temp_stats .= '<p><strong>'.__('Comment Members', 'wp-stats').'</strong></p>'."n";
$temp_stats .= '<ol>'."n";
$temp_stats .= get_commentmembersstats(5, 0, false);
@@ -492,7 +492,7 @@
$temp_stats .= '<h2 id="MiscStats">'.__('Misc Stats', 'wp-stats').'</h2>'."n";
// Post Categories
- if($stats_display['post_cats'] === 1) {
+ if((int) ($stats_display['post_cats'] ?? 0) === 1) {
$temp_stats .= '<p><strong>'.__('Post Categories', 'wp-stats').'</strong></p>'."n";
$temp_stats .= '<ul>'."n";
$temp_stats .= get_postcats(false);
@@ -500,14 +500,14 @@
}
// Link Categories
- if($stats_display['link_cats'] === 1) {
+ if((int) ($stats_display['link_cats'] ?? 0) === 1) {
$temp_stats .= '<p><strong>'.__('Link Categories', 'wp-stats').'</strong></p>'."n";
$temp_stats .= '<ul>'."n";
$temp_stats .= get_linkcats(false);
$temp_stats .= '</ul>'."n";
}
- if($stats_display['tags_list'] === 1) {
+ if((int) ($stats_display['tags_list'] ?? 0) === 1) {
$temp_stats .= '<p><strong>'.__('Tags List', 'wp-stats').'</strong></p>'."n";
$temp_stats .= '<ul>'."n";
$temp_stats .= get_tags_list(false);
@@ -525,10 +525,8 @@
$perpage = 30;
// Comment Author Link
$comment_author_link = urlencode($comment_author);
- // Comment Author SQL
- $comment_author_sql = $wpdb->escape($comment_author);
// Total Comments Posted By User
- $totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments INNER JOIN $wpdb->posts ON $wpdb->comments.comment_post_ID = $wpdb->posts.ID WHERE comment_author = '$comment_author_sql' AND comment_approved = '1' AND comment_type = 'commment' AND post_date < '".current_time('mysql')."' AND post_status = 'publish' AND post_password = ''");
+ $totalcomments = $wpdb->get_var($wpdb->prepare("SELECT COUNT(comment_ID) FROM $wpdb->comments INNER JOIN $wpdb->posts ON $wpdb->comments.comment_post_ID = $wpdb->posts.ID WHERE comment_author = %s AND comment_approved = '1' AND comment_type = 'comment' AND post_date < %s AND post_status = 'publish' AND post_password = ''", $comment_author, current_time('mysql')));
// Calculate Paging
$numposts = $totalcomments;
$max_page = ceil($numposts/$perpage);
@@ -567,8 +565,8 @@
}
// Getting The Comments
- $gmz_comments = $wpdb->get_results("SELECT $wpdb->posts.*, $wpdb->comments.* FROM $wpdb->comments INNER JOIN $wpdb->posts ON $wpdb->comments.comment_post_ID = $wpdb->posts.ID WHERE comment_author = '$comment_author_sql' AND comment_approved = '1' AND post_date < '".current_time('mysql')."' AND post_status = 'publish' AND post_password = '' ORDER BY comment_post_ID DESC, comment_date DESC LIMIT $offset, $perpage");
- $temp_stats .= '<h2>'.__('Comments Posted By', 'wp-stats').' '.$comment_author.'</h2>';
+ $gmz_comments = $wpdb->get_results($wpdb->prepare("SELECT $wpdb->posts.*, $wpdb->comments.* FROM $wpdb->comments INNER JOIN $wpdb->posts ON $wpdb->comments.comment_post_ID = $wpdb->posts.ID WHERE comment_author = %s AND comment_approved = '1' AND comment_type = 'comment' AND post_date < %s AND post_status = 'publish' AND post_password = '' ORDER BY comment_post_ID DESC, comment_date DESC LIMIT %d, %d", $comment_author, current_time('mysql'), $offset, $perpage));
+ $temp_stats .= '<h2>'.__('Comments Posted By', 'wp-stats').' '.esc_html($comment_author).'</h2>';
$temp_stats .= '<p>'.sprintf(__('Displaying <strong>%s</strong> To <strong>%s</strong> Of <strong>%s</strong> Comments', 'wp-stats'), number_format_i18n($display_on_page), number_format_i18n($max_on_page), number_format_i18n($numposts)).'</p>';
@@ -587,20 +585,20 @@
if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) !== $post->post_password) {
// If New Title, Print It Out
if($post_title !== $cache_post_title) {
- $temp_stats .= '<p><strong><a href="'.get_permalink().'" title="'.__('Posted On', 'wp-stats')." $post_date">".__('Protected', 'wp-stats').": $post_title</a></strong></p>";
+ $temp_stats .= '<p><strong><a href="'.esc_url(get_permalink()).'" title="'.esc_attr(__('Posted On', 'wp-stats')." $post_date").'">'.__('Protected', 'wp-stats').": ".esc_html($post_title)."</a></strong></p>";
$temp_stats .= '<blockquote>'.__('Comments Protected', 'wp-stats').'</blockquote>';
}
} else {
// If New Title, Print It Out
if($post_title !== $cache_post_title) {
- $temp_stats .= "<p><strong><a href="".get_permalink()."" title="".__('Posted On', 'wp-stats')." $post_date">$post_title</a></strong></p>";
+ $temp_stats .= "<p><strong><a href="".esc_url(get_permalink())."" title="".esc_attr(__('Posted On', 'wp-stats')." $post_date")."">".esc_html($post_title)."</a></strong></p>";
}
$temp_stats .= "<blockquote>$comment_content<p><a href="".get_permalink()."#comment-$comment_id" title="".sprintf(__('View the comment posted by %s', 'wp-stats'), $comment_author2)."">»</a> ".__('Posted By', 'wp-stats')." <strong>$comment_author2</strong> ".__('On', 'wp-stats')." $comment_date</p></blockquote>";
}
$cache_post_title = $post_title;
}
} else {
- $temp_stats .= "<p>$comment_author ".__('has not made any comments yet.', 'wp-stats')."</p>";
+ $temp_stats .= "<p>".esc_html($comment_author)." ".__('has not made any comments yet.', 'wp-stats')."</p>";
}
// Comments Paging
@@ -848,9 +846,25 @@
}
}
+### Function: Default Stats To Display
+# Single source of truth for the stats_display keys. Companion plugins that add
+# their own checkbox should register its key via the filter.
+function stats_display_defaults() {
+ return apply_filters( 'wp_stats_display_defaults', array(
+ 'total_stats' => 1, 'email' => 1, 'polls' => 1, 'ratings' => 1,
+ 'views' => 1, 'useronline' => 1, 'recent_posts' => 1,
+ 'recent_comments' => 1, 'commented_post' => 1, 'commented_page' => 0,
+ 'emailed_most_post' => 1, 'emailed_most_page' => 0,
+ 'rated_highest_post' => 1, 'rated_highest_page' => 0,
+ 'rated_most_post' => 1, 'rated_most_page' => 0,
+ 'viewed_most_post' => 1, 'viewed_most_page' => 0,
+ 'authors' => 1, 'comment_members' => 1, 'post_cats' => 1,
+ 'link_cats' => 1, 'tags_list' => 0,
+ ) );
+}
+
function stats_activate() {
- $stats_display = array( 'total_stats' => 1, 'email' => 1, 'polls' => 1, 'ratings' => 1, 'views' => 1, 'useronline' => 1, 'recent_posts' => 1, 'recent_comments' => 1, 'commented_post' => 1, 'commented_page' => 0, 'emailed_most_post' => 1, 'emailed_most_page' => 0, 'rated_highest_post' => 1, 'rated_highest_page' => 0, 'rated_most_post' => 1, 'rated_most_page' => 0, 'viewed_most_post' => 1, 'viewed_most_page' => 0, 'authors' => 1, 'comment_members' => 1, 'post_cats' => 1, 'link_cats' => 1 );
add_option( 'stats_mostlimit', 10, 'Stats Most Limit' );
- add_option( 'stats_display', $stats_display, 'Stats To Display' );
+ add_option( 'stats_display', stats_display_defaults(), 'Stats To Display' );
add_option( 'stats_url', esc_url( get_option( 'siteurl' ) ) .'/stats/', 'Stats URL' );
}
No newline at end of file