Function get_page_of_comment() returns incorrect page numbers
|Reported by:||GregMulhauser||Owned by:|
The function get_page_of_comment(), defined in /wp-includes/comment.php for WordPress 2.7, returns wildly incorrect results in cases where the database includes spam trackbacks or pingbacks. The reason is that the DB query on line 595 does not include "comment_approved = 1" and therefore incorrectly counts unapproved trackback and pingback spam (not to mention non-spam comments in moderation). As far as I can tell from browsing my DB, although spam comments have their comment_type changed to 'spam' in the database, trackbacks and pingbacks still retain their original comment_type.
As a newbie to the WordPress Trac, I'm afraid I don't know how to provide a diff, but the full correct query is as follows:
$oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 1 AND comment_post_ID = %d AND comment_parent = 0 AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );
The upshot is that without the above fix, comment URLs in several places (e.g., RSS feeds) may point to non-existent pages.
All the best,
Change History (18)
comment:1 GregMulhauser — 5 years ago
- Component changed from General to Comments
- Owner anonymous deleted
- Resolution fixed deleted
- Severity changed from major to normal
- Status changed from closed to reopened
- Summary changed from Function get_page_of_comment() returns incorrect page numbers -- fix included to Function get_page_of_comment() returns incorrect page numbers