Make WordPress Core

Changeset 35691


Ignore:
Timestamp:
11/18/2015 09:33:03 PM (9 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/menu.php

    r35590 r35691  
    6868// $menu[20] = Pages
    6969
    70 $awaiting_mod = wp_count_comments();
    71 $awaiting_mod = $awaiting_mod->moderated;
    72 $menu[25] = array( sprintf( __('Comments %s'), "<span class='awaiting-mod count-$awaiting_mod'><span class='pending-count'>" . number_format_i18n($awaiting_mod) . "</span></span>" ), 'edit_posts', 'edit-comments.php', '', 'menu-top menu-icon-comments', 'menu-comments', 'dashicons-admin-comments' );
    73 unset($awaiting_mod);
     70// Avoid the comment count query for users who cannot edit_posts.
     71if ( current_user_can( 'edit_posts' ) ) {
     72    $awaiting_mod = wp_count_comments();
     73    $awaiting_mod = $awaiting_mod->moderated;
     74    $menu[25] = array(
     75        sprintf( __( 'Comments %s' ), '<span class="awaiting-mod count-' . absint( $awaiting_mod ) . '"><span class="pending-count">' . number_format_i18n( $awaiting_mod ) . '</span></span>' ),
     76        'edit_posts',
     77        'edit-comments.php',
     78        '',
     79        'menu-top menu-icon-comments',
     80        'menu-comments',
     81        'dashicons-admin-comments',
     82    );
     83    unset( $awaiting_mod );
     84}
    7485
    7586$submenu[ 'edit-comments.php' ][0] = array( __('All Comments'), 'edit_posts', 'edit-comments.php' );
Note: See TracChangeset for help on using the changeset viewer.