diff --git a/wp-admin/menu.php b/wp-admin/menu.php index e39d638ea..3db528fa9 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -20,7 +20,8 @@ elseif (strpos($_SERVER['REQUEST_URI'], 'link-add.php') !== false) else $menu[10] = array(__('Manage'), 'edit_posts', 'edit.php'); -$awaiting_mod = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'"); +$awaiting_mod = wp_count_comments(); +$awaiting_mod = $awaiting_mod->moderated; $menu[15] = array(__('Design'), 'switch_themes', 'themes.php'); $menu[20] = array( sprintf( __('Comments %s'), "$awaiting_mod" ), 'edit_posts', 'edit-comments.php'); $menu[30] = array(__('Settings'), 'manage_options', 'options-general.php'); diff --git a/wp-includes/comment.php b/wp-includes/comment.php index b402dbd8c..cfd585661 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -451,6 +451,11 @@ function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_age function wp_count_comments() { global $wpdb; + $count = wp_cache_get('comments', 'counts'); + + if ( false !== $count ) + return $count; + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} GROUP BY comment_approved", ARRAY_A ); $stats = array( ); @@ -464,7 +469,10 @@ function wp_count_comments() { $stats[$key] = 0; } - return (object) $stats; + $stats = (object) $stats; + wp_cache_set('comments', $stats, 'counts'); + + return $stats; } /**