Comments: update Comment counts dynamically in the Right Now widget based on moderation actions in the Activity widget.

Fixes #10422.

Built from https://develop.svn.wordpress.org/trunk@34500


git-svn-id: http://core.svn.wordpress.org/trunk@34464 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-09-24 15:53:25 +00:00
parent 9dba452afc
commit 5b9af35c4c
5 changed files with 70 additions and 18 deletions

View File

@ -351,6 +351,8 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
$time = time();
$comment = get_comment( $comment_id );
$counts = wp_count_comments();
$x = new WP_Ajax_Response( array(
'what' => 'comment',
// Here for completeness - not used.
@ -358,7 +360,16 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
'supplemental' => array(
'status' => $comment ? $comment->comment_approved : '',
'postId' => $comment ? $comment->comment_post_ID : '',
'time' => $time
'time' => $time,
'in_moderation' => $counts->moderated,
'i18n_comments_text' => sprintf(
_n( '%s Comment', '%s Comments', $counts->approved ),
number_format_i18n( $counts->approved )
),
'i18n_moderation_text' => sprintf(
_nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ),
number_format_i18n( $counts->moderated )
)
)
) );
$x->send();
@ -1049,8 +1060,23 @@ function wp_ajax_replyto_comment( $action ) {
'position' => $position
);
if ( $comment_auto_approved )
$response['supplemental'] = array( 'parent_approved' => $parent->comment_ID, 'parent_post_id' => $parent->comment_post_ID );
$counts = wp_count_comments();
$response['supplemental'] = array(
'in_moderation' => $counts->moderated,
'i18n_comments_text' => sprintf(
_n( '%s Comment', '%s Comments', $counts->approved ),
number_format_i18n( $counts->approved )
),
'i18n_moderation_text' => sprintf(
_nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ),
number_format_i18n( $counts->moderated )
)
);
if ( $comment_auto_approved ) {
$response['supplemental']['parent_approved'] = $parent->comment_ID;
$response['supplemental']['parent_post_id'] = $parent->comment_post_ID;
}
$x = new WP_Ajax_Response();
$x->add( $response );

View File

@ -259,13 +259,15 @@ function wp_dashboard_right_now() {
?>
<li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
<?php
if ( $num_comm->moderated ) {
/* translators: Number of comments in moderation */
$text = sprintf( _nx( '%s in moderation', '%s in moderation', $num_comm->moderated, 'comments' ), number_format_i18n( $num_comm->moderated ) );
?>
<li class="comment-mod-count"><a href="edit-comments.php?comment_status=moderated"><?php echo $text; ?></a></li>
<?php
<li class="comment-mod-count<?php
if ( ! $num_comm->moderated ) {
echo ' hidden';
}
?>"><a href="edit-comments.php?comment_status=moderated"><?php echo $text; ?></a></li>
<?php
}
/**
@ -554,7 +556,7 @@ function wp_dashboard_recent_drafts( $drafts = false ) {
* @param bool $show_date
*/
function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
$GLOBALS['comment'] =& $comment;
$GLOBALS['comment'] = clone $comment;
if ( $comment->comment_post_ID > 0 && current_user_can( 'edit_post', $comment->comment_post_ID ) ) {
$comment_post_title = _draft_or_post_title( $comment->comment_post_ID );

View File

@ -3,7 +3,7 @@ var setCommentsList, theList, theExtraList, commentReply;
(function($) {
var getCount, updateCount, updateCountText, updatePending, updateApproved,
updateHtmlTitle, adminTitle = document.title;
updateHtmlTitle, updateDashboardText, adminTitle = document.title;
setCommentsList = function() {
var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
@ -19,6 +19,10 @@ setCommentsList = function() {
var editRow, replyID, replyButton, response,
c = $( '#' + settings.element );
if ( true !== settings.parsed ) {
response = settings.parsed.responses[0];
}
editRow = $('#replyrow');
replyID = $('#comment_ID', editRow).val();
replyButton = $('#replybtn', editRow);
@ -36,10 +40,10 @@ setCommentsList = function() {
}
diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
if ( true !== settings.parsed && settings.parsed.responses.length ) {
response = settings.parsed.responses[0].supplemental;
updatePending( diff, response.postId );
updateApproved( -1 * diff, response.postId );
if ( response ) {
updateDashboardText( response.supplemental );
updatePending( diff, response.supplemental.postId );
updateApproved( -1 * diff, response.supplemental.postId );
} else {
updatePending( diff );
updateApproved( -1 * diff );
@ -277,12 +281,26 @@ setCommentsList = function() {
});
};
updateDashboardText = function ( response ) {
if ( ! isDashboard || ! response || ! response.i18n_comments_text ) {
return;
}
var rightNow = $( '#dashboard_right_now' );
$( '.comment-count a', rightNow ).text( response.i18n_comments_text );
$( '.comment-mod-count a', rightNow ).text( response.i18n_moderation_text )
.parent()
[ response.in_moderation > 0 ? 'removeClass' : 'addClass' ]( 'hidden' );
};
// 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, animated, animatedCallback,
response = true === settings.parsed ? {} : settings.parsed.responses[0],
commentStatus = true === settings.parsed ? '' : response.supplemental.status,
commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
newTotal = true === settings.parsed ? '' : response.supplemental,
targetParent = $( settings.target ).parent(),
commentRow = $('#' + settings.element),
@ -294,6 +312,8 @@ setCommentsList = function() {
spammed = commentRow.hasClass( 'spam' ),
trashed = commentRow.hasClass( 'trash' );
updateDashboardText( newTotal );
// the order of these checks is important
// .unspam can also have .approve or .unapprove
// .untrash can also have .approve or .unapprove
@ -771,6 +791,10 @@ commentReply = {
}
}
if ( r.supplemental.i18n_comments_text ) {
updateDashboardText( r.supplemental );
}
c = $.trim(r.data); // Trim leading whitespaces
$(c).hide();
$('#replyrow').after(c);

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-34499';
$wp_version = '4.4-alpha-34500';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.