Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/js/_enqueues/admin/edit-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 || '';
Expand Down
2 changes: 2 additions & 0 deletions src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 ),
Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/tests/ajax/wpAjaxDeleteComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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).
*/
Expand Down
Loading