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

git-svn-id: http://svn.automattic.com/wordpress/trunk@12715 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2010-01-12 22:38:26 +00:00
parent 591a31a664
commit 2fabcf53fe
3 changed files with 25 additions and 19 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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 = "<a href='" . get_edit_post_link($post->ID) . "'>";