mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Consolidate get_pending_comments_num() queries. see #6770
git-svn-id: https://develop.svn.wordpress.org/trunk@7775 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -66,9 +66,28 @@ function get_comment_to_edit( $id ) {
|
||||
|
||||
function get_pending_comments_num( $post_id ) {
|
||||
global $wpdb;
|
||||
$post_id = (int) $post_id;
|
||||
$pending = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '0'", $post_id) );
|
||||
return $pending;
|
||||
|
||||
$single = false;
|
||||
if ( !is_array($post_id) ) {
|
||||
$post_id = (array) $post_id;
|
||||
$single = true;
|
||||
}
|
||||
$post_id = array_map('intval', $post_id);
|
||||
$post_id = "'" . implode("', '", $post_id) . "'";
|
||||
|
||||
$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_keyed = array();
|
||||
foreach ( $pending as $pend )
|
||||
$pending_keyed[$pend[0]] = $pend[1];
|
||||
|
||||
return $pending_keyed;
|
||||
}
|
||||
|
||||
// Add avatars to relevant places in admin, or try to
|
||||
|
||||
Reference in New Issue
Block a user