Update counts and pagination when trashing and moderating comments. Props garyc40, koopersmith, mdawaffe, nacin. fixes #15530
git-svn-id: http://svn.automattic.com/wordpress/trunk@17354 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
+29
-28
@@ -189,7 +189,7 @@ endif;
|
||||
* @param int $comment_id
|
||||
* @return die
|
||||
*/
|
||||
function _wp_ajax_delete_comment_response( $comment_id ) {
|
||||
function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
|
||||
$total = (int) @$_POST['_total'];
|
||||
$per_page = (int) @$_POST['_per_page'];
|
||||
$page = (int) @$_POST['_page'];
|
||||
@@ -198,43 +198,39 @@ function _wp_ajax_delete_comment_response( $comment_id ) {
|
||||
if ( !$total || !$per_page || !$page || !$url )
|
||||
die( (string) time() );
|
||||
|
||||
if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one)
|
||||
$total += $delta;
|
||||
if ( $total < 0 )
|
||||
$total = 0;
|
||||
|
||||
if ( 0 != $total % $per_page && 1 != mt_rand( 1, $per_page ) ) // Only do the expensive stuff on a page-break, and about 1 other time per page
|
||||
die( (string) time() );
|
||||
// Only do the expensive stuff on a page-break, and about 1 other time per page
|
||||
if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) {
|
||||
$post_id = 0;
|
||||
$status = 'total_comments'; // What type of comment count are we looking for?
|
||||
$parsed = parse_url( $url );
|
||||
if ( isset( $parsed['query'] ) ) {
|
||||
parse_str( $parsed['query'], $query_vars );
|
||||
if ( !empty( $query_vars['comment_status'] ) )
|
||||
$status = $query_vars['comment_status'];
|
||||
if ( !empty( $query_vars['p'] ) )
|
||||
$post_id = (int) $query_vars['p'];
|
||||
}
|
||||
|
||||
$post_id = 0;
|
||||
$status = 'total_comments'; // What type of comment count are we looking for?
|
||||
$parsed = parse_url( $url );
|
||||
if ( isset( $parsed['query'] ) ) {
|
||||
parse_str( $parsed['query'], $query_vars );
|
||||
if ( !empty( $query_vars['comment_status'] ) )
|
||||
$status = $query_vars['comment_status'];
|
||||
if ( !empty( $query_vars['p'] ) )
|
||||
$post_id = (int) $query_vars['p'];
|
||||
$comment_count = wp_count_comments($post_id);
|
||||
|
||||
if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count
|
||||
$total = $comment_count->$status;
|
||||
// else use the decremented value from above
|
||||
}
|
||||
|
||||
$comment_count = wp_count_comments($post_id);
|
||||
$time = time(); // The time since the last comment count
|
||||
|
||||
if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count
|
||||
$total = $comment_count->$status;
|
||||
// else use the decremented value from above
|
||||
|
||||
$page_links = paginate_links( array(
|
||||
'base' => add_query_arg( 'apage', '%#%', $url ),
|
||||
'format' => '',
|
||||
'prev_text' => __('«'),
|
||||
'next_text' => __('»'),
|
||||
'total' => ceil($total / $per_page),
|
||||
'current' => $page
|
||||
) );
|
||||
$x = new WP_Ajax_Response( array(
|
||||
'what' => 'comment',
|
||||
'id' => $comment_id, // here for completeness - not used
|
||||
'supplemental' => array(
|
||||
'pageLinks' => $page_links,
|
||||
'total_items_i18n' => sprintf( _n( '1 item', '%s items', $total ), number_format_i18n( $total ) ),
|
||||
'total_pages' => ceil( $total / $per_page ),
|
||||
'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),
|
||||
'total' => $total,
|
||||
'time' => $time
|
||||
)
|
||||
@@ -331,6 +327,7 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
||||
check_ajax_referer( "delete-comment_$id" );
|
||||
$status = wp_get_comment_status( $comment->comment_ID );
|
||||
|
||||
$delta = -1;
|
||||
if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
|
||||
if ( 'trash' == $status )
|
||||
die( (string) time() );
|
||||
@@ -339,6 +336,8 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
||||
if ( 'trash' != $status )
|
||||
die( (string) time() );
|
||||
$r = wp_untrash_comment( $comment->comment_ID );
|
||||
if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash
|
||||
$delta = 1;
|
||||
} elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
|
||||
if ( 'spam' == $status )
|
||||
die( (string) time() );
|
||||
@@ -347,6 +346,8 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
||||
if ( 'spam' != $status )
|
||||
die( (string) time() );
|
||||
$r = wp_unspam_comment( $comment->comment_ID );
|
||||
if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam
|
||||
$delta = 1;
|
||||
} elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
|
||||
$r = wp_delete_comment( $comment->comment_ID );
|
||||
} else {
|
||||
@@ -354,7 +355,7 @@ case 'delete-comment' : // On success, die with time() instead of 1
|
||||
}
|
||||
|
||||
if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
|
||||
_wp_ajax_delete_comment_response( $comment->comment_ID );
|
||||
_wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
|
||||
die( '0' );
|
||||
break;
|
||||
case 'delete-tag' :
|
||||
|
||||
Reference in New Issue
Block a user