Improve get_pending_comments_num() to be a little more predictable and revert the erroneous change in [12596]. See #11882.

git-svn-id: https://develop.svn.wordpress.org/trunk@12715 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Westwood 2010-01-12 22:38:26 +00:00
parent 4b4316bdf8
commit 60d271287e
3 changed files with 25 additions and 19 deletions

View File

@ -244,11 +244,8 @@ $_comment_post_ids = array();
foreach ( $_comments as $_c ) { foreach ( $_comments as $_c ) {
$_comment_post_ids[] = $_c->comment_post_ID; $_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 = get_pending_comments_num($_comment_post_ids);
$_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();
$comments = array_slice($_comments, 0, $comments_per_page); $comments = array_slice($_comments, 0, $comments_per_page);
$extra_comments = array_slice($_comments, $comments_per_page); $extra_comments = array_slice($_comments, $comments_per_page);

View File

@ -109,23 +109,32 @@ function get_pending_comments_num( $post_id ) {
$single = false; $single = false;
if ( !is_array($post_id) ) { if ( !is_array($post_id) ) {
$post_id = (array) $post_id; $post_id_array = (array) $post_id;
$single = true; $single = true;
} else {
$post_id_array = $post_id;
} }
$post_id = array_map('intval', $post_id); $post_id_array = array_map('intval', $post_id_array);
$post_id = "'" . implode("', '", $post_id) . "'"; $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 ); $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) ) if ( empty($pending) )
return 0; return 0;
else
if ( $single ) return absint($pending[0]['num_comments']);
return $pending[0][1]; }
$pending_keyed = array(); $pending_keyed = array();
// 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 ) foreach ( $pending as $pend )
$pending_keyed[$pend[0]] = $pend[1]; $pending_keyed[$pend['comment_post_ID']] = absint($pend['num_comments']);
return $pending_keyed; return $pending_keyed;
} }

View File

@ -2263,10 +2263,10 @@ function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true,
case 'response': case 'response':
if ( 'single' !== $mode ) { if ( 'single' !== $mode ) {
if ( isset( $_comment_pending_count[$post->ID] ) ) { if ( isset( $_comment_pending_count[$post->ID] ) ) {
$pending_comments = absint( $_comment_pending_count[$post->ID] ); $pending_comments = $_comment_pending_count[$post->ID];
} else { } else {
$_comment_pending_count_temp = get_pending_comments_num( array( $post->ID ) ); $_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 ) { if ( $user_can ) {
$post_link = "<a href='" . get_edit_post_link($post->ID) . "'>"; $post_link = "<a href='" . get_edit_post_link($post->ID) . "'>";