From b17cb707dc4aec5e2373f2c201ac29c07fbc4354 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 18 Nov 2015 21:34:26 +0000 Subject: [PATCH] Eliminate a db query when building the admin menu for non-privileged users. Users who cannot `edit_posts` do not see the Comments nav item anyway, so don't bother running a query that gets a comment count to display in the menu. Props bordoni, johnbillion. Fixes #19372. Built from https://develop.svn.wordpress.org/trunk@35691 git-svn-id: http://core.svn.wordpress.org/trunk@35655 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/menu.php | 19 +++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/wp-admin/menu.php b/wp-admin/menu.php index d04fd3c12f..64f80190cf 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -67,10 +67,21 @@ $menu[15] = array( __('Links'), 'manage_links', 'link-manager.php', '', 'menu-to // $menu[20] = Pages -$awaiting_mod = wp_count_comments(); -$awaiting_mod = $awaiting_mod->moderated; -$menu[25] = array( sprintf( __('Comments %s'), "" . number_format_i18n($awaiting_mod) . "" ), 'edit_posts', 'edit-comments.php', '', 'menu-top menu-icon-comments', 'menu-comments', 'dashicons-admin-comments' ); -unset($awaiting_mod); +// Avoid the comment count query for users who cannot edit_posts. +if ( current_user_can( 'edit_posts' ) ) { + $awaiting_mod = wp_count_comments(); + $awaiting_mod = $awaiting_mod->moderated; + $menu[25] = array( + sprintf( __( 'Comments %s' ), '' . number_format_i18n( $awaiting_mod ) . '' ), + 'edit_posts', + 'edit-comments.php', + '', + 'menu-top menu-icon-comments', + 'menu-comments', + 'dashicons-admin-comments', + ); + unset( $awaiting_mod ); +} $submenu[ 'edit-comments.php' ][0] = array( __('All Comments'), 'edit_posts', 'edit-comments.php' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index a57ed79e0e..777bae2568 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-beta4-35690'; +$wp_version = '4.4-beta4-35691'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.