Ticket #6770: get_comments_pending_num.diff
| File get_comments_pending_num.diff, 2.1 KB (added by , 18 years ago) |
|---|
-
wp-admin/includes/comment.php
66 66 67 67 function get_pending_comments_num( $post_id ) { 68 68 global $wpdb; 69 $post_id = (int) $post_id; 70 $pending = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '0'", $post_id) ); 71 return $pending; 69 70 $single = false; 71 if ( !is_array($post_id) ) { 72 $post_id = (array) $post_id; 73 $single = true; 74 } 75 $post_id = array_map('intval', $post_id); 76 $post_id = "'" . implode("', '", $post_id) . "'"; 77 78 $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 ); 79 80 if ( empty($pending) ) 81 return 0; 82 83 if ( $single ) 84 return $pending[0][1]; 85 86 $pending_keyed = array(); 87 foreach ( $pending as $pend ) 88 $pending_keyed[$pend[0]] = $pend[1]; 89 90 return $pending_keyed; 72 91 } 73 92 74 93 // Add avatars to relevant places in admin, or try to -
wp-admin/edit-post-rows.php
22 22 if ( have_posts() ) { 23 23 $bgcolor = ''; 24 24 add_filter('the_title','wp_specialchars'); 25 26 // Create array of post IDs. 27 $post_ids = array(); 28 foreach ( $wp_query->posts as $a_post ) 29 $post_ids[] = $a_post->ID; 30 31 $comment_pending_count = get_pending_comments_num($post_ids); 32 25 33 while (have_posts()) : the_post(); 26 34 $class = 'alternate' == $class ? '' : 'alternate'; 27 35 global $current_user; … … 113 121 ?> 114 122 <td class="num"><div class="post-com-count-wrapper"> 115 123 <?php 116 $left = get_pending_comments_num( $post->ID );124 $left = isset($comment_pending_count) ? $comment_pending_count[$post->ID] : 0; 117 125 $pending_phrase = sprintf( __('%s pending'), number_format( $left ) ); 118 126 if ( $left ) 119 127 echo '<strong>';