Comments: Update the Mine count after AJAX actions#12620
Comments: Update the Mine count after AJAX actions#12620ArkaPrabhaChowdhury wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the wp-admin Comments screen’s live counter updates by ensuring the “Mine” view count stays accurate after AJAX moderation and reply actions, using new server-provided metadata to determine whether a comment belongs to the current user.
Changes:
- Adds
supplemental.is_current_userto_wp_ajax_delete_comment_response()so the client can detect ownership. - Updates
edit-comments.jsto increment/decrement the “Mine” count after applicable AJAX actions. - Adds PHPUnit regression coverage verifying the new ownership metadata in the AJAX response.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
tests/phpunit/tests/ajax/wpAjaxDeleteComment.php |
Adds a test asserting the AJAX response includes an ownership flag for current-user comments. |
src/wp-admin/includes/ajax-actions.php |
Includes is_current_user ownership metadata in delete-comment AJAX responses. |
src/js/_enqueues/admin/edit-comments.js |
Uses ownership metadata to update the “Mine” counter after moderation actions; increments “Mine” after replies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ( response.supplemental && 1 === parseInt( response.supplemental.is_current_user, 10 ) ) { | ||
| updateCountText( 'span.mine-count', ( pendingDiff || 0 ) + ( approvedDiff || 0 ) ); | ||
| } |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Trac ticket: https://core.trac.wordpress.org/ticket/46017
Summary
Why
The comments screen already updates the All, Pending, Approved, Spam, and Trash counts after AJAX actions, but it does not update Mine. Moderation responses also did not expose enough information for the client to know whether the affected comment belonged to the current user.
Testing
npm run test:php -- --group ajax --filter "Tests_Ajax_wpAjax(DeleteComment|DimComment|ReplytoComment)"(18 tests, 132 assertions)npm run test:php -- --group ajax --filter Tests_Ajax_wpAjaxDeleteComment(6 tests, 85 assertions)phpcs.xml.diston both touched PHP filessrc/js/_enqueues/admin/edit-comments.js