diff --git a/wp-admin/edit-comments.php b/wp-admin/edit-comments.php index 24982a9cbb..e5b01a65ff 100644 --- a/wp-admin/edit-comments.php +++ b/wp-admin/edit-comments.php @@ -244,11 +244,8 @@ $_comment_post_ids = array(); foreach ( $_comments as $_c ) { $_comment_post_ids[] = $_c->comment_post_ID; } -$_comment_pending_count_temp = (array) get_pending_comments_num($_comment_post_ids); -foreach ( (array) $_comment_post_ids as $_cpid ) - $_comment_pending_count[$_cpid] = isset( $_comment_pending_count_temp[$_cpid] ) ? $_comment_pending_count_temp[$_cpid] : 0; -if ( empty($_comment_pending_count) ) - $_comment_pending_count = array(); + +$_comment_pending_count = get_pending_comments_num($_comment_post_ids); $comments = array_slice($_comments, 0, $comments_per_page); $extra_comments = array_slice($_comments, $comments_per_page); diff --git a/wp-admin/includes/comment.php b/wp-admin/includes/comment.php index 528049f2f5..c535824908 100644 --- a/wp-admin/includes/comment.php +++ b/wp-admin/includes/comment.php @@ -109,23 +109,32 @@ function get_pending_comments_num( $post_id ) { $single = false; if ( !is_array($post_id) ) { - $post_id = (array) $post_id; + $post_id_array = (array) $post_id; $single = true; + } else { + $post_id_array = $post_id; } - $post_id = array_map('intval', $post_id); - $post_id = "'" . implode("', '", $post_id) . "'"; + $post_id_array = array_map('intval', $post_id_array); + $post_id_in = "'" . implode("', '", $post_id_array) . "'"; - $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_N ); - - if ( empty($pending) ) - return 0; - - if ( $single ) - return $pending[0][1]; + $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_A ); + if ( $single ) { + if ( empty($pending) ) + return 0; + else + return absint($pending[0]['num_comments']); + } + $pending_keyed = array(); - foreach ( $pending as $pend ) - $pending_keyed[$pend[0]] = $pend[1]; + + // Default to zero pending for all posts in request + foreach ( $post_id_array as $id ) + $pending_keyed[$id] = 0; + + if ( !empty($pending) ) + foreach ( $pending as $pend ) + $pending_keyed[$pend['comment_post_ID']] = absint($pend['num_comments']); return $pending_keyed; } diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index ab737aa033..c2d85827dc 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -2263,10 +2263,10 @@ function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true, case 'response': if ( 'single' !== $mode ) { if ( isset( $_comment_pending_count[$post->ID] ) ) { - $pending_comments = absint( $_comment_pending_count[$post->ID] ); + $pending_comments = $_comment_pending_count[$post->ID]; } else { $_comment_pending_count_temp = get_pending_comments_num( array( $post->ID ) ); - $pending_comments = $_comment_pending_count[$post->ID] = $_comment_pending_count_temp; + $pending_comments = $_comment_pending_count[$post->ID] = $_comment_pending_count_temp[$post->ID]; } if ( $user_can ) { $post_link = "";