Make WordPress Core

Changeset 16079


Ignore:
Timestamp:
10/29/2010 03:36:45 PM (15 years ago)
Author:
ryan
Message:

Add Updates menu to admin bar. see #14772

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/admin-bar.php

    r16078 r16079  
    244244     if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
    245245        $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) );
     246}
     247
     248function wp_admin_bar_updates_menu() {
     249    global $wp_admin_bar;
     250
     251    if ( !current_user_can('install_plugins') )
     252        return;
     253
     254    $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
     255    $update_plugins = get_site_transient( 'update_plugins' );
     256    if ( !empty($update_plugins->response) )
     257        $plugin_update_count = count( $update_plugins->response );
     258    $update_themes = get_site_transient( 'update_themes' );
     259    if ( !empty($update_themes->response) )
     260        $theme_update_count = count( $update_themes->response );
     261    /* @todo get_core_updates() is only available on admin page loads
     262    $update_wordpress = get_core_updates( array('dismissed' => false) );
     263    if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) )
     264        $wordpress_update_count = 1;
     265    */
     266 
     267    $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count;
     268
     269    if ( !$update_count )
     270        return;
     271
     272    $update_title = array();
     273    if ( $wordpress_update_count )
     274        $update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count);
     275    if ( $plugin_update_count )
     276        $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count);
     277    if ( $theme_update_count )
     278        $update_title[] = sprintf(_n('%d Theme Update', '%d Themes Updates', $theme_update_count), $theme_update_count);
     279
     280    $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : '';
     281
     282    $update_title = sprintf( __('Updates %s'), "<span class='update-plugins count-$update_count' title='$update_title'><span class='update-count'>" . number_format_i18n($update_count) . "</span></span>" );
     283
     284    // @todo styling for awaiting mod count. Don't show count if zero?
     285    $wp_admin_bar->add_menu( array( 'id' => 'updates', 'title' => $update_title, 'href' => admin_url('update-core.php') ) );
    246286}
    247287
  • trunk/wp-includes/admin-bar/admin-bar-class.php

    r16078 r16079  
    183183        add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_comments_menu', 60 );
    184184        add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_appearance_menu', 70 );
    185         add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_shortlink_menu', 80 );
     185        add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_updates_menu', 80 );
     186        add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_shortlink_menu', 90 );
    186187       
    187188        if ( is_multisite() && is_super_admin() && function_exists('wp_admin_bar_superadmin_settings_menu') )
Note: See TracChangeset for help on using the changeset viewer.