From b4c01a843acce1e3c1802ea0377dd9df4264bc77 Mon Sep 17 00:00:00 2001 From: Kamal Hosen Date: Thu, 13 Aug 2026 21:32:31 +0600 Subject: [PATCH] Comments: Update the "Mine" count after AJAX moderation and reply actions. The comments list table updates the All, Approved, Pending, Spam, and Trash counts via AJAX, but the Mine count never changed because the moderation/reply responses did not indicate whether the affected comment belonged to the current user. Adds an isCurrentUserComment flag to the AJAX supplemental data and uses it in edit-comments.js to keep the Mine count in sync. Props itzmekhokan, peterwilsoncc, arkaprabhachowdhury. Fixes #46017 --- src/js/_enqueues/admin/edit-comments.js | 9 ++++++++- src/wp-admin/includes/ajax-actions.php | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/js/_enqueues/admin/edit-comments.js b/src/js/_enqueues/admin/edit-comments.js index 78ee78de759ff..ccb49da74ceed 100644 --- a/src/js/_enqueues/admin/edit-comments.js +++ b/src/js/_enqueues/admin/edit-comments.js @@ -480,12 +480,13 @@ window.setCommentsList = function() { response = true === settings.parsed ? {} : settings.parsed.responses[0], commentStatus = true === settings.parsed ? '' : response.supplemental.status, commentPostId = true === settings.parsed ? '' : response.supplemental.postId, + isCurrentUserComment = true === settings.parsed ? false : !! parseInt( response.supplemental.isCurrentUserComment, 10 ), newTotal = true === settings.parsed ? '' : response.supplemental, targetParent = $( settings.target ).parent(), commentRow = $('#' + settings.element), - spamDiff, trashDiff, pendingDiff, approvedDiff, + spamDiff, trashDiff, pendingDiff, approvedDiff, mineDiff, /* * As `wpList` toggles only the `unapproved` class, the approved comment @@ -623,6 +624,11 @@ window.setCommentsList = function() { } } + mineDiff = ( pendingDiff || 0 ) + ( approvedDiff || 0 ); + if ( mineDiff && isCurrentUserComment ) { + updateCountText( 'span.mine-count', mineDiff ); + } + if ( pendingDiff ) { updatePending( pendingDiff, commentPostId ); updateCountText( 'span.all-count', pendingDiff ); @@ -1155,6 +1161,7 @@ window.commentReply = { updateInModerationText( r.supplemental ); updateApproved( 1, r.supplemental.parent_post_id ); updateCountText( 'span.all-count', 1 ); + updateCountText( 'span.mine-count', 1 ); } r.data = r.data || ''; diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index a04de73bd64e4..8fca8c2fe8f10 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -488,6 +488,7 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { 'supplemental' => array( 'status' => $comment_status, 'postId' => $comment ? $comment->comment_post_ID : '', + 'isCurrentUserComment' => (int) ( $comment && get_current_user_id() === (int) $comment->user_id ), 'time' => $time, 'in_moderation' => $counts->moderated, 'i18n_comments_text' => sprintf( @@ -559,6 +560,7 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { 'supplemental' => array( 'status' => $comment ? $comment->comment_approved : '', 'postId' => $comment ? $comment->comment_post_ID : '', + 'isCurrentUserComment' => (int) ( $comment && get_current_user_id() === (int) $comment->user_id ), /* translators: %s: Number of comments. */ 'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ), 'total_pages' => (int) ceil( $total / $per_page ),