WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/26/2011 06:39:57 PM (10 years ago)
Author:
ryan
Message:

Consolidate update count code into wp_get_update_data(). Props mitchoyoshitaka. fixes #17694

File:
1 edited

Legend:

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

    r18254 r18468  
    3131}
    3232
    33 if ( ! is_multisite() || is_super_admin() ) {
    34     $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
    35 
    36     if ( current_user_can( 'update_plugins' ) ) {
    37         $update_plugins = get_site_transient( 'update_plugins' );
    38         if ( ! empty( $update_plugins->response ) )
    39             $plugin_update_count = count( $update_plugins->response );
    40     }
    41 
    42     if ( current_user_can( 'update_themes' ) ) {
    43         $update_themes = get_site_transient( 'update_themes' );
    44         if ( !empty($update_themes->response) )
    45             $theme_update_count = count( $update_themes->response );
    46     }
    47 
    48     if ( current_user_can( 'update_core' ) ) {
    49         $update_wordpress = get_core_updates( array('dismissed' => false) );
    50         if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') )
    51             $wordpress_update_count = 1;
    52     }
    53 
    54     $total_update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count;
    55     $update_title = array();
    56     if ( $wordpress_update_count )
    57         $update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count);
    58     if ( $plugin_update_count )
    59         $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count);
    60     if ( $theme_update_count )
    61         $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $theme_update_count), $theme_update_count);
    62 
    63     $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : '';
    64 }
     33if ( ! is_multisite() || is_super_admin() )
     34    $update_data = wp_get_update_data();
    6535
    6636if ( ! is_multisite() ) {
    67     $submenu[ 'index.php' ][10] = array( sprintf( __('Updates %s'), "<span class='update-plugins count-$total_update_count' title='$update_title'><span class='update-count'>" . number_format_i18n($total_update_count) . "</span></span>" ), 'update_core',  'update-core.php');
    68 }
    69 
    70 unset($theme_update_count, $wordpress_update_count, $update_themes, $update_plugins, $update_wordpress);
     37    $submenu[ 'index.php' ][10] = array( sprintf( __('Updates %s'), "<span class='update-plugins count-{$update_data['counts']['total']}' title='{$update_data['title']}'><span class='update-count'>" . number_format_i18n($update_data['counts']['total']) . "</span></span>" ), 'update_core',  'update-core.php');
     38}
    7139
    7240$menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
     
    177145$menu_perms = get_site_option( 'menu_items', array() );
    178146if ( ! is_multisite() || is_super_admin() || ! empty( $menu_perms['plugins'] ) ) {
     147    if ( ! isset( $update_data ) )
     148        $update_data = wp_get_update_data();
     149
    179150    $count = '';
    180151    if ( ! is_multisite() && current_user_can( 'update_plugins' ) )
    181         $count = "<span class='update-plugins count-$plugin_update_count'><span class='plugin-count'>" . number_format_i18n($plugin_update_count) . "</span></span>";
     152        $count = "<span class='update-plugins count-{$update_data['counts']['plugins']}'><span class='plugin-count'>" . number_format_i18n($update_data['counts']['plugins']) . "</span></span>";
    182153
    183154    $menu[65] = array( sprintf( __('Plugins %s'), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' );
     
    191162        }
    192163}
    193 unset($menu_perms, $update_plugins, $plugin_update_count);
     164unset($menu_perms, $update_data);
    194165
    195166if ( current_user_can('list_users') )
Note: See TracChangeset for help on using the changeset viewer.