Skip to content

Open comment links on the page the comment is actually on - #3678

Open
pfefferle wants to merge 4 commits into
trunkfrom
fix/comment-permalink-page
Open

Open comment links on the page the comment is actually on#3678
pfefferle wants to merge 4 commits into
trunkfrom
fix/comment-permalink-page

Conversation

@pfefferle

Copy link
Copy Markdown
Member

Proposed changes:

get_page_of_comment() counts the comments older than the given one with type => 'all', the one value that makes WP_Comment_Query skip every exclusion. comments_template() renders the same post with our comment types hidden. So on a post with a few likes or reposts older than a comment, core places that comment on a later page than the one it actually renders on, and get_comment_link() emits a cpage the comment is not on. Every #comment- permalink, reply notification link and feed link is affected once a post collects enough reactions.

Reproduced with three reactions older than one comment, two per page:

get_page_of_comment() says page 2 ; the list actually renders it on page 1
permalink: ...?p=10&cpage=2#comment-5

This hooks get_page_of_comment_query_args so the count uses the same exclusion the list does. It steps aside on ActivityPub requests, where the list shows everything, and when a caller asks for a specific type.

Core has had the same bug with its own note type since 6.9, and fixes it the same way in WordPress/wordpress-develop#12310, which is still open, so it does not help us yet.

Split out of #2981 on request, it is a different bug in the same file.

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Enable paged comments with 2 per page, oldest first.
  • On a post, create three likes or reposts, then one regular comment after them.
  • Before: the comment's permalink carries cpage=2, but the comment renders on page 1.
  • After: no cpage, the link opens on the page the comment is on.

test_get_page_of_comment_ignores_hidden_reactions covers it and fails with the hook removed.

Changelog entry

In the branch as .github/changelog/fix-comment-permalink-page, patch / fixed.

Copilot AI lite review requested due to automatic review settings August 28, 2026 08:46
@pfefferle pfefferle self-assigned this Aug 28, 2026
@pfefferle
pfefferle requested a review from a team August 28, 2026 08:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect #comment-… permalinks on posts with many ActivityPub reactions by ensuring get_page_of_comment() uses the same comment-type exclusions as the rendered comment list (so it doesn’t compute a later cpage than where the comment actually appears).

Changes:

  • Hook get_page_of_comment_query_args to exclude ActivityPub reaction comment types from the “older comments” count (except on ActivityPub requests or when a specific type is requested).
  • Add a PHPUnit regression test covering the incorrect cpage behavior.
  • Add a patch-level changelog entry describing the user-visible fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
includes/class-comment.php Adds get_page_of_comment_query_args() filter to keep comment pagination math aligned with rendered exclusions.
tests/phpunit/tests/includes/class-test-comment.php Adds a regression test ensuring get_page_of_comment()/get_comment_link() don’t point at the wrong cpage when older reactions exist.
.github/changelog/fix-comment-permalink-page Documents the permalink pagination fix for release notes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread includes/class-comment.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants