Opened 44 hours ago
Last modified 44 hours ago
#66272 new defect (bug)
Comments: "Mine" view count not updated via AJAX after moderation actions
| Reported by: | abditsori | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | Awaiting Review |
| Component: | Comments | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
On the Comments screen (edit-comments.php), performing an AJAX moderation
action — Approve, Unapprove, Spam, Trash, Delete Permanently, or Undo —
live-updates several of the view tab counts in the DOM without a full page
reload. edit-comments.js's delAfter handler bumps:
span.all-countspan.pending-count(viaupdatePending())span.approved-count(viaupdateApproved())span.spam-countspan.trash-count
span.mine-count is never touched by this code. As a result, after e.g.
trashing or deleting one of your own comments via the inline row actions,
the "Mine (N)" tab keeps showing the old count until the page is fully
reloaded — inconsistent with every other tab, which updates immediately.
Steps to reproduce:
- Log in as a user who has left at least one comment on the site
(comment's
user_idmatches the logged-in user). - Go to Comments in wp-admin. Note the "Mine (N)" count in the view tabs.
- Click the "Mine" tab to filter to your own comments.
- Use the inline "Trash" (or "Delete Permanently" / "Approve" / etc.) link on one of your own comments.
Expected: "Mine (N)" decrements immediately, matching how "All" and
"Trash" update.
Actual: "Mine (N)" stays at its old value until the page is reloaded.
Root cause: "Mine" uses the same status scope as "All" (approved +
pending comments; see WP_Comments_List_Table::get_views(), which queries
with no status arg and defaults to 'all'), just filtered to the
current user's own comments via user_id. The AJAX handler updates "All"
but has no way to know, client-side, whether the affected comment belongs
to the current user, so it was never extended to also update "Mine".
Suggested fix: render a data-comment-user-id attribute on each comment
row (WP_Comments_List_Table::single_row()), localize the current user's
ID to the admin-comments script, and in edit-comments.js compare the
two to decide whether to also bump span.mine-count alongside
span.all-count for the same pendingDiff/approvedDiff changes.
Change History (1)
This ticket was mentioned in PR #14114 on WordPress/wordpress-develop by @abditsori.
44 hours ago
#1
- Keywords has-patch has-unit-tests added
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: https://core.trac.wordpress.org/ticket/66272
Summary
On the Comments screen, performing an AJAX moderation action (Approve, Unapprove, Spam, Trash, Delete Permanently, or Undo) live-updates several view tab counts in the DOM without a full page reload —
edit-comments.js'sdelAfterhandler bumpsspan.all-count,span.pending-count(viaupdatePending),span.approved-count(viaupdateApproved),span.spam-count, andspan.trash-count.The
span.mine-countbadge is never touched by this code, so after e.g. deleting one of your own comments via AJAX, the "Mine (N)" tab keeps showing the old count until the page is fully reloaded — inconsistent with every other tab."Mine" uses the same status scope as "All" (approved + pending comments; see
WP_Comments_List_Table::get_views(), which queries with nostatusarg, defaulting to'all'), just filtered to the current user's own comments. So it needs the samependingDiff/approvedDiffupdates thatall-countgets, applied only when the affected comment belongs to the current user.Changes
WP_Comments_List_Table::single_row()now renders adata-comment-user-idattribute on each comment<tr>.admin-commentsscript is localized with the current user's ID (adminCommentsSettings.currentUserId).edit-comments.jscompares the acted-upon row'sdata-comment-user-idto the current user ID and, when they match, also updatesspan.mine-countalongsidespan.all-countfor bothpendingDiffandapprovedDiff.test_single_row_includes_comment_user_id_for_mine_count_trackingtowpCommentsListTable.php.Test plan
php -lon the changed PHP files;node --checkandnpx eslinton the changed JS file (no errors).Tests_Admin_wpCommentsListTableandTests_Admin_wpPostCommentsListTable— 12 tests total, all passing.class-wp-comments-list-table.php(nodata-comment-user-idattribute) and passes with the fix.span.mine-countafter an AJAX action) isn't covered by PHPUnit — manually verified the logic by tracingdelAfterinedit-comments.js, but a browser/QUnit check of the actual tab count updating live would be good before merging.