diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php
index 77c32b05ed..ccb8aa7939 100644
--- a/src/wp-admin/includes/ajax-actions.php
+++ b/src/wp-admin/includes/ajax-actions.php
@@ -347,8 +347,21 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
$url = isset( $_POST['_url'] ) ? esc_url_raw( $_POST['_url'] ) : '';
// JS didn't send us everything we need to know. Just die with success message
- if ( !$total || !$per_page || !$page || !$url )
- wp_die( time() );
+ if ( ! $total || ! $per_page || ! $page || ! $url ) {
+ $time = time();
+ $comment = get_comment( $comment_id );
+
+ $x = new WP_Ajax_Response( array(
+ 'what' => 'comment',
+ // Here for completeness - not used.
+ 'id' => $comment_id,
+ 'supplemental' => array(
+ 'status' => $comment ? $comment->comment_approved : '',
+ 'time' => $time
+ )
+ ) );
+ $x->send();
+ }
$total += $delta;
if ( $total < 0 )
@@ -377,12 +390,14 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
// The time since the last comment count.
$time = time();
+ $comment = get_comment( $comment_id );
$x = new WP_Ajax_Response( array(
'what' => 'comment',
// Here for completeness - not used.
'id' => $comment_id,
'supplemental' => array(
+ 'status' => $comment ? $comment->comment_approved : '',
'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
'total_pages' => ceil( $total / $per_page ),
'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),
diff --git a/src/wp-admin/includes/class-wp-comments-list-table.php b/src/wp-admin/includes/class-wp-comments-list-table.php
index fcfcd1e36b..52d3f50ba6 100644
--- a/src/wp-admin/includes/class-wp-comments-list-table.php
+++ b/src/wp-admin/includes/class-wp-comments-list-table.php
@@ -198,7 +198,7 @@ class WP_Comments_List_Table extends WP_List_Table {
$stati = array(
'all' => _nx_noop('All', 'All', 'comments'), // singular not used
'moderated' => _n_noop('Pending (%s)', 'Pending (%s)'),
- 'approved' => _n_noop('Approved', 'Approved'), // singular not used
+ 'approved' => _n_noop('Approved (%s)', 'Approved (%s)'),
'spam' => _n_noop('Spam (%s)', 'Spam (%s)'),
'trash' => _n_noop('Trash (%s)', 'Trash (%s)')
);
diff --git a/src/wp-admin/js/edit-comments.js b/src/wp-admin/js/edit-comments.js
index bea253cec0..6a8bb24d5b 100644
--- a/src/wp-admin/js/edit-comments.js
+++ b/src/wp-admin/js/edit-comments.js
@@ -12,6 +12,7 @@ setCommentsList = function() {
perPageInput = $('input[name="_per_page"]', '#comments-form');
pageInput = $('input[name="_page"]', '#comments-form');
+ // this fires when viewing "All"
dimAfter = function( r, settings ) {
var editRow, replyID, replyButton,
c = $( '#' + settings.element );
@@ -34,6 +35,7 @@ setCommentsList = function() {
diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
updatePending( diff );
+ updateCountText( 'span.approved-count', -1 * diff );
};
// Send current total, page, per_page and url
@@ -137,53 +139,166 @@ setCommentsList = function() {
});
};
+ updateCountText = function( selector, diff ) {
+ $( selector ).each(function() {
+ var a = $(this), n = getCount(a) + diff;
+ if ( n < 1 ) {
+ n = 0;
+ }
+ updateCount( a, n );
+ });
+ };
+
// In admin-ajax.php, we send back the unix time stamp instead of 1 on success
delAfter = function( r, settings ) {
- var total_items_i18n, total, spam, trash, pending,
- untrash = $(settings.target).parent().is('span.untrash'),
- unspam = $(settings.target).parent().is('span.unspam'),
- unapproved = $('#' + settings.element).is('.unapproved');
+ var total_items_i18n, total,
+ response = true === settings.parsed ? {} : settings.parsed.responses[0],
+ commentStatus = true === settings.parsed ? '' : response.supplemental.status,
- function getUpdate(s) {
- if ( $(settings.target).parent().is('span.' + s) )
- return 1;
- else if ( $('#' + settings.element).is('.' + s) )
- return -1;
+ targetParent = $( settings.target ).parent(),
+ commentRow = $('#' + settings.element),
- return 0;
+ spamDiff, trashDiff, pendingDiff, approvedDiff,
+
+ approved = commentRow.hasClass( 'approved' ),
+ unapproved = commentRow.hasClass( 'unapproved' ),
+ spammed = commentRow.hasClass( 'spam' ),
+ trashed = commentRow.hasClass( 'trash' );
+
+ // the order of these checks is important
+ // .unspam can also have .approve or .unapprove
+ // .untrash can also have .approve or .unapprove
+
+ if ( targetParent.is( 'span.undo' ) ) {
+ // the comment was spammed
+ if ( targetParent.hasClass( 'unspam' ) ) {
+ spamDiff = -1;
+
+ if ( 'trash' === commentStatus ) {
+ trashDiff = 1;
+ } else if ( '1' === commentStatus ) {
+ approvedDiff = 1;
+ } else if ( '0' === commentStatus ) {
+ pendingDiff = 1;
+ }
+
+ // the comment was trashed
+ } else if ( targetParent.hasClass( 'untrash' ) ) {
+ trashDiff = -1;
+
+ if ( 'spam' === commentStatus ) {
+ spamDiff = 1;
+ } else if ( '1' === commentStatus ) {
+ approvedDiff = 1;
+ } else if ( '0' === commentStatus ) {
+ pendingDiff = 1;
+ }
+ }
+
+ // user clicked "Spam"
+ } else if ( targetParent.is( 'span.spam' ) ) {
+ // the comment is currently approved
+ if ( approved ) {
+ approvedDiff = -1;
+ // the comment is currently pending
+ } else if ( unapproved ) {
+ pendingDiff = -1;
+ // the comment was in the trash
+ } else if ( trashed ) {
+ trashDiff = -1;
+ }
+ // you can't spam an item on the spam screen
+ spamDiff = 1;
+
+ // user clicked "Unspam"
+ } else if ( targetParent.is( 'span.unspam' ) ) {
+ if ( approved ) {
+ pendingDiff = 1;
+ } else if ( unapproved ) {
+ approvedDiff = 1;
+ } else if ( trashed ) {
+ // the comment was previously approved
+ if ( targetParent.hasClass( 'approve' ) ) {
+ approvedDiff = 1;
+ // the comment was previously pending
+ } else if ( targetParent.hasClass( 'unapprove' ) ) {
+ pendingDiff = 1;
+ }
+ } else if ( spammed ) {
+ if ( targetParent.hasClass( 'approve' ) ) {
+ approvedDiff = 1;
+
+ } else if ( targetParent.hasClass( 'unapprove' ) ) {
+ pendingDiff = 1;
+ }
+ }
+ // you can Unspam an item on the spam screen
+ spamDiff = -1;
+
+ // user clicked "Trash"
+ } else if ( targetParent.is( 'span.trash' ) ) {
+ if ( approved ) {
+ approvedDiff = -1;
+ } else if ( unapproved ) {
+ pendingDiff = -1;
+ // the comment was in the spam queue
+ } else if ( spammed ) {
+ spamDiff = -1;
+ }
+ // you can't trash an item on the trash screen
+ trashDiff = 1;
+
+ // user clicked "Restore"
+ } else if ( targetParent.is( 'span.untrash' ) ) {
+ if ( approved ) {
+ pendingDiff = 1;
+ } else if ( unapproved ) {
+ approvedDiff = 1;
+ } else if ( trashed ) {
+ if ( targetParent.hasClass( 'approve' ) ) {
+ approvedDiff = 1;
+ } else if ( targetParent.hasClass( 'unapprove' ) ) {
+ pendingDiff = 1;
+ }
+ }
+ // you can't go from trash to spam
+ // you can untrash on the trash screen
+ trashDiff = -1;
+
+ // User clicked "Approve"
+ } else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) {
+ approvedDiff = 1;
+ pendingDiff = -1;
+
+ // User clicked "Unapprove"
+ } else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) {
+ approvedDiff = -1;
+ pendingDiff = 1;
+
+ // User clicked "Delete Permanently"
+ } else if ( targetParent.is( 'span.delete' ) ) {
+ if ( spammed ) {
+ spamDiff = -1;
+ } else if ( trashed ) {
+ trashDiff = -1;
+ }
}
- if ( untrash )
- trash = -1;
- else
- trash = getUpdate('trash');
-
- if ( unspam )
- spam = -1;
- else
- spam = getUpdate('spam');
-
- if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) {
- // a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending,
- // or a trash/spam of a pending comment was undone
- pending = 1;
- } else if ( unapproved ) {
- // a pending comment was trashed/spammed/approved
- pending = -1;
+ if ( pendingDiff ) {
+ updatePending( pendingDiff );
}
- if ( pending )
- updatePending(pending);
+ if ( approvedDiff ) {
+ updateCountText( 'span.approved-count', approvedDiff );
+ }
- $('span.spam-count').each( function() {
- var a = $(this), n = getCount(a) + spam;
- updateCount(a, n);
- });
+ if ( spamDiff ) {
+ updateCountText( 'span.spam-count', spamDiff );
+ }
- $('span.trash-count').each( function() {
- var a = $(this), n = getCount(a) + trash;
- updateCount(a, n);
- });
+ if ( trashDiff ) {
+ updateCountText( 'span.trash-count', trashDiff );
+ }
if ( ! $('#dashboard_right_now').length ) {
total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
@@ -195,20 +310,24 @@ setCommentsList = function() {
if ( total < 0 )
total = 0;
- if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
- total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
- if ( total_items_i18n ) {
- $('.displaying-num').text( total_items_i18n );
- $('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
- $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
+ if ( 'object' === typeof r ) {
+ if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) {
+ total_items_i18n = response.supplemental.total_items_i18n || '';
+ if ( total_items_i18n ) {
+ $('.displaying-num').text( total_items_i18n );
+ $('.total-pages').text( response.supplemental.total_pages_i18n );
+ $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val());
+ }
+ updateTotalCount( total, response.supplemental.time, true );
+ } else if ( response.supplemental.time ) {
+ updateTotalCount( total, response.supplemental.time, false );
}
- updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
} else {
updateTotalCount( total, r, false );
}
}
- if ( ! theExtraList || theExtraList.size() === 0 || theExtraList.children().size() === 0 || untrash || unspam ) {
+ if ( ! theExtraList || theExtraList.size() === 0 || theExtraList.children().size() === 0 ) {
return;
}