Make WordPress Core

Opened 4 years ago

Last modified 17 months ago

#18603 assigned defect (bug)

Comments on pages which exceed paginate settings create erroneous permalinks

Reported by: msagman Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.2.1
Component: Comments Keywords: needs-patch
Focuses: Cc:


On my website, clicking on any of the Recent Comments that possess large numbers of comments exceeding paginate settings (50 comments) present erroneous permalinks. Only the posts containing enough comments on page 3 or higher present these improperly constructed links that take users to the wrong page (a page that does not contain the comment in question). The problem does not occur on pages containing a limited number of comments. So far, we have removed our Thesis theme and changed to the standard WP default theme. And we've deactivated all plugins. Yet neither solution appears to resolve the issue. Thanks for your consideration. You may view this issue live at http://www.dogfoodadvisor.com

Change History (18)

#1 @SergeyBiryukov
4 years ago

So get_page_of_comment() returns wrong number?

Could not reproduce this on a clean install with 5 pages of comments. Looks more like a support request to me.

#2 @solarissmoke
4 years ago

  • Keywords reporter-feedback close added

From your description it sounds like the issue is with the "Recent Comments" sidebar widget, in which case you need to talk to the author of that plugin. If the issue can be reproduced in a clean installation of Wordpress, without any plugins installed, please give the steps to reproduce.

#3 @solarissmoke
4 years ago

Oops, just realised Recent Comments is part of core, not a plugin. In any case, I can't reproduce either.

#4 @msagman
4 years ago

Thanks for looking. I've left a thread on the support forum. May I ask, is it possible some other file may have been modified by a plugin and have been corrupted (for example, htaccess) that could be causing this? Have absolutely no idea where to look. Thanks.

#5 @SergeyBiryukov
4 years ago

If it was .htaccess, the links would at least look correct when moving cursor over them.

One of the problem links contains comment-page-14/#comment-37218, whereas the proper link for that comment is comment-page-17/#comment-37218. So I suspect get_page_of_comment() returns a wrong number for some reason.

#6 @billerickson
4 years ago

So could this be caused by #8973?

I've been trying to help Mike with this issue. To give you a little more info on it:

  • I cannot reproduce it on a clean WordPress installation
  • When we disable all plugins and switch to default theme, the issue still persists

#7 @msagman
4 years ago

I think we've found the problem. And it does appear to be located in the core function of WP in the get_page_of_comment() lines. You should be able to reproduce the problem. As I understand it, it has to do with the logic of the way WP computes the page number. It appears to have something to do with whether the comments are approved or not. So, it only affects the posts containing the largest number of comments and the longest history.

Here's a copy of what my software technician reported to me. And after testing his changes, the problem disappeared and was fixed:

In /wp-includes/comment.php on line 813:
$oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );

In order to determine the correct page number for the most recent comment link you must not include approved comments and parent comments in the query… After changing the query above to the following I was able to determine the correct number of $oldercoms variable, thus affecting the math on line 820, by executing:

$oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );

Finally, I changed the math logic to:
return round( ( $oldercoms + 1 ) / $argsper_page? );

Thanks for your help.

#8 @msagman
4 years ago

  • Keywords reporter-feedback close removed

#9 @msagman
4 years ago

Please forgive my lack of understanding of how the review process works, but are you awaiting a response from me? Do I need to do something else? Have not seen any further responses or entries since my last comment. Is this bug still under review? I removed the two tags. Should I have not done that? Please be sure to see my last entry which shows you how to reproduce this same issue in a clean install. You must have sufficient comments on a number of comment pages. WP uses the wrong logic by including both approved and parent comments in the query. Please notice the get_page_of_comment() function is not set up properly. Thanks.

#10 @SergeyBiryukov
4 years ago

Thank you for the report, now it makes sense.

I'll look closer into this and #8973.

#11 @msagman
4 years ago

The problem I describe in this bug report is NOT fixed with the above code I previously submitted. I have figured out what you need to do to reproduce the issue. The problem of defective pagination only occurs when there has been more threaded responses than the number of comments per page set in the paginate feature. Even if WP is set for no threaded responses.

Today in my Wordpress research my technician concluded that the comment page calculation was thrown off when the comment's parent column was set. We tested this together and found that Wordpress sets the comment parent when replying to user's comments as an admin regardless of the threading setting under "Discussions" settings.

To fix this we ran the following SQL query on the comments table:

UPDATE wp_comments SET comment_parent = 0 WHERE comment_parent > 0

#12 @billerickson
4 years ago

  • Keywords dev-feedback added

I think I'm having the same issue on my more popular posts as well. On this post ( http://www.billerickson.net/wordpress-metaboxes ) I have 128 comments, 50 of which are top level comments. In Settings > Discussion I have it set to 50 top level comments per page.

But when I view the comments from the backend and look at their URL (or if I were using the Recent Comments widget), they link to the second page where the comment isn't.

The second to last comment (logesh) has this URL: http://www.billerickson.net/wordpress-metaboxes/comment-page-2/#comment-5608
The last comment (billerickson) has this URL: http://www.billerickson.net/wordpress-metaboxes/comment-page-2/#comment-5623

#13 @ericlewis
3 years ago

This sounds a duplicate of #8973, which @billerickson suggested.

The issue can be replicated by making multiple comments on a post until the comments pagination # is hit, after which the new comment URL will still be returned as comment-page-1. Unless there's a different bug reproduction process which hasn't been realized and detailed yet.

#14 follow-up: @SergeyBiryukov
3 years ago

  • Keywords needs-testing added

Not sure if this is an exact duplicate of #8973. That ticket fixes the issue with including current user's unmoderated comments, while this one has to do with comment threading (I didn't have any comments on the reporter's site and still noticed a problem mentioned in comment:5).

#15 in reply to: ↑ 14 @ericlewis
3 years ago

  • Keywords needs-steps-to-reproduce added

Replying to SergeyBiryukov:

Not sure if this is an exact duplicate of #8973. That ticket fixes the issue with including current user's unmoderated comments, while this one has to do with comment threading (I didn't have any comments on the reporter's site and still noticed a problem mentioned in comment:5).

Yep, you're right.

I couldn't reproduce this after tinkering with some comments. Steps-to-reproduce would help.

Last edited 3 years ago by ericlewis (previous) (diff)

#16 @jaredatch
3 years ago

  • Cc jared@… added

#17 @jaredatch
3 years ago

Any update on this?

What do we need for a fix? I have a client with this issue so I can do testing/provide feedback if needed.

Basically if someone has pagination and thousands of comments, the Recent Comments widget is worthless as it is now.

#18 @wonderboymusic
17 months ago

  • Keywords needs-patch added; dev-feedback needs-testing needs-steps-to-reproduce removed
  • Milestone changed from Awaiting Review to Future Release
  • Owner Mike Sagman http://www.dogfoodadvisor.com deleted
  • Status changed from new to assigned
Note: See TracTickets for help on using tickets.