diff --git a/src/js/_enqueues/admin/edit-comments.js b/src/js/_enqueues/admin/edit-comments.js index 78ee78de759ff..65e6830977ee0 100644 --- a/src/js/_enqueues/admin/edit-comments.js +++ b/src/js/_enqueues/admin/edit-comments.js @@ -485,7 +485,7 @@ window.setCommentsList = function() { 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 +623,11 @@ window.setCommentsList = function() { } } + mineDiff = ( pendingDiff || 0 ) + ( approvedDiff || 0 ); + if ( mineDiff && response.supplemental && 1 === parseInt( response.supplemental.is_current_user, 10 ) ) { + updateCountText( 'span.mine-count', mineDiff ); + } + if ( pendingDiff ) { updatePending( pendingDiff, commentPostId ); updateCountText( 'span.all-count', pendingDiff ); @@ -1155,6 +1160,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..9482dec1ade86 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 : '', + 'is_current_user' => (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 : '', + 'is_current_user' => (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 ), diff --git a/tests/phpunit/tests/ajax/wpAjaxDeleteComment.php b/tests/phpunit/tests/ajax/wpAjaxDeleteComment.php index 26b14dd221b79..8095bce8322e3 100644 --- a/tests/phpunit/tests/ajax/wpAjaxDeleteComment.php +++ b/tests/phpunit/tests/ajax/wpAjaxDeleteComment.php @@ -272,6 +272,7 @@ public function _test_double_action( $comment, $action ) { * @covers ::_wp_ajax_delete_comment_response */ public function test_ajax_comment_trash_actions_as_administrator() { + // Test trash/untrash. $this->_test_as_admin( self::$comments[0], 'trash' ); $this->_test_as_admin( self::$comments[0], 'untrash' ); @@ -284,6 +285,43 @@ public function test_ajax_comment_trash_actions_as_administrator() { $this->_test_as_admin( self::$comments[2], 'delete' ); } + /** + * Tests that the response identifies a comment by the current user. + * + * @ticket 46017 + * @covers ::_wp_ajax_delete_comment_response + */ + public function test_ajax_comment_response_identifies_current_user_comment() { + + $this->_setRole( 'administrator' ); + + $comment = self::$comments[3]; + wp_update_comment( + array( + 'comment_ID' => $comment->comment_ID, + 'user_id' => get_current_user_id(), + ) + ); + + $_POST['id'] = $comment->comment_ID; + $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID ); + $_POST['trash'] = '1'; + $_POST['_total'] = count( self::$comments ); + $_POST['_per_page'] = '100'; + $_POST['_page'] = '1'; + $_POST['_url'] = admin_url( 'edit-comments.php' ); + + try { + $this->_handleAjax( 'delete-comment' ); + } catch ( WPAjaxDieContinueException $e ) { + unset( $e ); + } + + $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA ); + + $this->assertSame( '1', (string) $xml->response[0]->comment[0]->supplemental[0]->is_current_user[0] ); + } + /** * Deletes a comment as a subscriber (expects permission denied). */