mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-12 13:44:21 +01:00
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:
parent
9dba452afc
commit
5b9af35c4c
@ -351,6 +351,8 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
|
|||||||
$time = time();
|
$time = time();
|
||||||
$comment = get_comment( $comment_id );
|
$comment = get_comment( $comment_id );
|
||||||
|
|
||||||
|
$counts = wp_count_comments();
|
||||||
|
|
||||||
$x = new WP_Ajax_Response( array(
|
$x = new WP_Ajax_Response( array(
|
||||||
'what' => 'comment',
|
'what' => 'comment',
|
||||||
// Here for completeness - not used.
|
// Here for completeness - not used.
|
||||||
@ -358,7 +360,16 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
|
|||||||
'supplemental' => array(
|
'supplemental' => array(
|
||||||
'status' => $comment ? $comment->comment_approved : '',
|
'status' => $comment ? $comment->comment_approved : '',
|
||||||
'postId' => $comment ? $comment->comment_post_ID : '',
|
'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();
|
$x->send();
|
||||||
@ -1049,8 +1060,23 @@ function wp_ajax_replyto_comment( $action ) {
|
|||||||
'position' => $position
|
'position' => $position
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( $comment_auto_approved )
|
$counts = wp_count_comments();
|
||||||
$response['supplemental'] = array( 'parent_approved' => $parent->comment_ID, 'parent_post_id' => $parent->comment_post_ID );
|
$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 = new WP_Ajax_Response();
|
||||||
$x->add( $response );
|
$x->add( $response );
|
||||||
|
@ -259,13 +259,15 @@ function wp_dashboard_right_now() {
|
|||||||
?>
|
?>
|
||||||
<li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
|
<li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
|
||||||
<?php
|
<?php
|
||||||
if ( $num_comm->moderated ) {
|
|
||||||
/* translators: Number of comments in moderation */
|
/* 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 ) );
|
$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>
|
<li class="comment-mod-count<?php
|
||||||
<?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
|
* @param bool $show_date
|
||||||
*/
|
*/
|
||||||
function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
|
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 ) ) {
|
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 );
|
$comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
|
||||||
|
@ -3,7 +3,7 @@ var setCommentsList, theList, theExtraList, commentReply;
|
|||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
var getCount, updateCount, updateCountText, updatePending, updateApproved,
|
var getCount, updateCount, updateCountText, updatePending, updateApproved,
|
||||||
updateHtmlTitle, adminTitle = document.title;
|
updateHtmlTitle, updateDashboardText, adminTitle = document.title;
|
||||||
|
|
||||||
setCommentsList = function() {
|
setCommentsList = function() {
|
||||||
var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
|
var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
|
||||||
@ -19,6 +19,10 @@ setCommentsList = function() {
|
|||||||
var editRow, replyID, replyButton, response,
|
var editRow, replyID, replyButton, response,
|
||||||
c = $( '#' + settings.element );
|
c = $( '#' + settings.element );
|
||||||
|
|
||||||
|
if ( true !== settings.parsed ) {
|
||||||
|
response = settings.parsed.responses[0];
|
||||||
|
}
|
||||||
|
|
||||||
editRow = $('#replyrow');
|
editRow = $('#replyrow');
|
||||||
replyID = $('#comment_ID', editRow).val();
|
replyID = $('#comment_ID', editRow).val();
|
||||||
replyButton = $('#replybtn', editRow);
|
replyButton = $('#replybtn', editRow);
|
||||||
@ -36,10 +40,10 @@ setCommentsList = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
|
diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
|
||||||
if ( true !== settings.parsed && settings.parsed.responses.length ) {
|
if ( response ) {
|
||||||
response = settings.parsed.responses[0].supplemental;
|
updateDashboardText( response.supplemental );
|
||||||
updatePending( diff, response.postId );
|
updatePending( diff, response.supplemental.postId );
|
||||||
updateApproved( -1 * diff, response.postId );
|
updateApproved( -1 * diff, response.supplemental.postId );
|
||||||
} else {
|
} else {
|
||||||
updatePending( diff );
|
updatePending( diff );
|
||||||
updateApproved( -1 * 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
|
// In admin-ajax.php, we send back the unix time stamp instead of 1 on success
|
||||||
delAfter = function( r, settings ) {
|
delAfter = function( r, settings ) {
|
||||||
var total_items_i18n, total, animated, animatedCallback,
|
var total_items_i18n, total, animated, animatedCallback,
|
||||||
response = true === settings.parsed ? {} : settings.parsed.responses[0],
|
response = true === settings.parsed ? {} : settings.parsed.responses[0],
|
||||||
commentStatus = true === settings.parsed ? '' : response.supplemental.status,
|
commentStatus = true === settings.parsed ? '' : response.supplemental.status,
|
||||||
commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
|
commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
|
||||||
|
newTotal = true === settings.parsed ? '' : response.supplemental,
|
||||||
|
|
||||||
targetParent = $( settings.target ).parent(),
|
targetParent = $( settings.target ).parent(),
|
||||||
commentRow = $('#' + settings.element),
|
commentRow = $('#' + settings.element),
|
||||||
@ -294,6 +312,8 @@ setCommentsList = function() {
|
|||||||
spammed = commentRow.hasClass( 'spam' ),
|
spammed = commentRow.hasClass( 'spam' ),
|
||||||
trashed = commentRow.hasClass( 'trash' );
|
trashed = commentRow.hasClass( 'trash' );
|
||||||
|
|
||||||
|
updateDashboardText( newTotal );
|
||||||
|
|
||||||
// the order of these checks is important
|
// the order of these checks is important
|
||||||
// .unspam can also have .approve or .unapprove
|
// .unspam can also have .approve or .unapprove
|
||||||
// .untrash 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 = $.trim(r.data); // Trim leading whitespaces
|
||||||
$(c).hide();
|
$(c).hide();
|
||||||
$('#replyrow').after(c);
|
$('#replyrow').after(c);
|
||||||
|
2
wp-admin/js/edit-comments.min.js
vendored
2
wp-admin/js/edit-comments.min.js
vendored
File diff suppressed because one or more lines are too long
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user