From 4f3bdf22268e3af76449b439b8ed513f58ae9f38 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 29 Oct 2010 15:36:45 +0000 Subject: [PATCH] Add Updates menu to admin bar. see #14772 git-svn-id: http://svn.automattic.com/wordpress/trunk@16079 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/admin-bar.php | 40 +++++++++++++++++++++++ wp-includes/admin-bar/admin-bar-class.php | 3 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index a4678214b1..44d27030a7 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -245,6 +245,46 @@ function wp_admin_bar_appearance_menu() { $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) ); } +function wp_admin_bar_updates_menu() { + global $wp_admin_bar; + + if ( !current_user_can('install_plugins') ) + return; + + $plugin_update_count = $theme_update_count = $wordpress_update_count = 0; + $update_plugins = get_site_transient( 'update_plugins' ); + if ( !empty($update_plugins->response) ) + $plugin_update_count = count( $update_plugins->response ); + $update_themes = get_site_transient( 'update_themes' ); + if ( !empty($update_themes->response) ) + $theme_update_count = count( $update_themes->response ); + /* @todo get_core_updates() is only available on admin page loads + $update_wordpress = get_core_updates( array('dismissed' => false) ); + if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) ) + $wordpress_update_count = 1; + */ + + $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count; + + if ( !$update_count ) + return; + + $update_title = array(); + if ( $wordpress_update_count ) + $update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count); + if ( $plugin_update_count ) + $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count); + if ( $theme_update_count ) + $update_title[] = sprintf(_n('%d Theme Update', '%d Themes Updates', $theme_update_count), $theme_update_count); + + $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : ''; + + $update_title = sprintf( __('Updates %s'), "" . number_format_i18n($update_count) . "" ); + + // @todo styling for awaiting mod count. Don't show count if zero? + $wp_admin_bar->add_menu( array( 'id' => 'updates', 'title' => $update_title, 'href' => admin_url('update-core.php') ) ); +} + /** * Style and scripts for the admin bar. * diff --git a/wp-includes/admin-bar/admin-bar-class.php b/wp-includes/admin-bar/admin-bar-class.php index 7603dd9af1..da512e2ea3 100644 --- a/wp-includes/admin-bar/admin-bar-class.php +++ b/wp-includes/admin-bar/admin-bar-class.php @@ -182,7 +182,8 @@ class WP_Admin_Bar { add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_new_content_menu', 50 ); add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_comments_menu', 60 ); add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_appearance_menu', 70 ); - add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_shortlink_menu', 80 ); + add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_updates_menu', 80 ); + add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_shortlink_menu', 90 ); if ( is_multisite() && is_super_admin() && function_exists('wp_admin_bar_superadmin_settings_menu') ) add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_superadmin_settings_menu', 1000 );