A recent post on WP Tavern mentioned a proposal to save a mouse click when updating plugins. The proposal (trac ticket #27303) missed the boat for WordPress 3.9 and now 4.0. The post author suggested adding a similar clickable link for the ‘Pending Comments’ counter.

In the comments I asked whether it could be achieved right now via ‘add_filter’. I then searched the WordPress source and found that there isn’t a good filter for this. One could use the ‘add_menu_classes’ filter in wp-admin/includes/menu.php to hack the change but that would require regular expressions to change the menu html. Far from clean.

Then dlouwe suggested adding an “Updates” link to the “Plugins” menu when updates are available, and a “Pending” link when there were unmoderated comments. I searched the WordPress source again and found the wp_get_update_data() function that returns whether there are updates. It returns an array like:

array (
  'counts' => 
  array (
    'plugins' => 1,
    'themes' => 0,
    'wordpress' => 0,
    'translations' => 0,
    'total' => 1,
  'title' => '1 Plugin Update',

so it was a simple matter of checking the ‘plugins’ element to determine whether to add the ‘Updates’ menu item. The wp_count_comments() function returns an object that includes a count of comments awaiting moderation.

The final code is:

// In response to post at:
// http://wptavern.com/a-proposed-enhancement-that-saves-a-mouse-click-when-upgrading-wordpress-plugins
add_action('admin_menu', 'add_plugin_updates_menu');
function add_plugin_updates_menu() {
  $update_data = wp_get_update_data();
  // Add "Updates" menu item when plugin updates available.
  if($update_data['counts']['plugins'] > 0) {
    add_plugins_page( 'Not displayed', 'Updates', 'update_plugins', 'plugins.php?plugin_status=upgrade');
  // Add "Pending" menu item when there are comments awaiting moderation.
  $awaiting_mod = wp_count_comments();
  $awaiting_mod = $awaiting_mod->moderated;
  if($awaiting_mod) {
    add_comments_page( 'Not displayed', 'Pending', 'moderate_comments', 'edit-comments.php?comment_status=moderated');


I was determined to make the suggested change to the Comments menu number bubble. I was able to hack $menu via the ‘add_menu_classes’ filter to change the Comments number link. Unfortunately menu links have a ‘display: block’ style so the number is pushed onto a new line. You could workaround this by adding a style: ‘#wp-admin-bar-new-content a { display:inline;}’

Screenshot: http://imgur.com/mWtYECW

// Solution for http://wptavern.com/a-proposed-enhancement-that-saves-a-mouse-click-when-upgrading-wordpress-plugins#comment-56798
add_filter('add_menu_classes', 'um_add_clickable_numbers');
function um_add_clickable_numbers($menu) {
  foreach ($menu as $key => $menu_item) {
    if (strpos($menu_item, 'Comments ') == 0) {
      $re = "/(Comments) (.*)$/";
      $subst = '$1</a> <a href="edit-comments.php?comment_status=moderated">$2';
      $menu[$key][0] = preg_replace($re, $subst, $menu[$key][0], 1);

  return $menu;