WordPress.org

Make WordPress Core

Changeset 18468


Ignore:
Timestamp:
07/26/11 18:39:57 (4 years ago)
Author:
ryan
Message:

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

Location:
trunk
Files:
4 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') ) 
  • trunk/wp-admin/network/menu.php

    r18157 r18468  
    2222$submenu['users.php'][10]  = array( _x('Add New', 'user'), 'create_users', 'user-new.php' ); 
    2323 
    24 if ( current_user_can( 'update_themes' ) ) { 
    25     $plugin_update_count = $theme_update_count = $wordpress_update_count = 0; 
    26     $update_themes = get_site_transient( 'update_themes' ); 
    27     if ( !empty($update_themes->response) ) 
    28         $theme_update_count = count( $update_themes->response ); 
    29     $menu[15] = array(sprintf( __( 'Themes %s' ), "<span class='update-plugins count-$theme_update_count'><span class='theme-count'>" . number_format_i18n( $theme_update_count ) . "</span></span>" ), 'manage_network_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' ); 
     24$update_data = wp_get_update_data(); 
     25 
     26if ( $update_data['counts']['themes'] ) { 
     27    $menu[15] = array(sprintf( __( 'Themes %s' ), "<span class='update-plugins count-{$update_data['counts']['themes']}'><span class='theme-count'>" . number_format_i18n( $update_data['counts']['themes'] ) . "</span></span>" ), 'manage_network_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' ); 
    3028} else { 
    3129    $menu[15] = array( __( 'Themes' ), 'manage_network_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' ); 
     
    3634 
    3735if ( current_user_can( 'update_plugins' ) ) { 
    38     $update_plugins = get_site_transient( 'update_plugins' ); 
    39     if ( !empty($update_plugins->response) ) 
    40         $plugin_update_count = count( $update_plugins->response ); 
    41     $menu[20] = array( sprintf( __( 'Plugins %s' ), "<span class='update-plugins count-$plugin_update_count'><span class='plugin-count'>" . number_format_i18n( $plugin_update_count ) . "</span></span>" ), 'manage_network_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div'); 
     36    $menu[20] = array( sprintf( __( 'Plugins %s' ), "<span class='update-plugins count-{$update_data['counts']['plugins']}'><span class='plugin-count'>" . number_format_i18n( $update_data['counts']['plugins'] ) . "</span></span>" ), 'manage_network_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div'); 
    4237} else { 
    4338    $menu[20] = array( __('Plugins'), 'manage_network_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' ); 
     
    5449} 
    5550 
    56 if ( current_user_can( 'update_core' ) ) { 
    57     $update_wordpress = get_core_updates( array('dismissed' => false) ); 
    58     if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) ) 
    59         $wordpress_update_count = 1; 
    60      
    61     $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count; 
    62     $update_title = array(); 
    63     if ( $wordpress_update_count ) 
    64         $update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count); 
    65     if ( $plugin_update_count ) 
    66         $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count); 
    67     if ( $theme_update_count ) 
    68         $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $theme_update_count), $theme_update_count); 
    69      
    70     $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : ''; 
    71      
    72     $menu[30] = array( sprintf( __( 'Updates %s' ), "<span class='update-plugins count-$update_count' title='$update_title'><span class='update-count'>" . number_format_i18n($update_count) . "</span></span>" ), 'manage_network', 'upgrade.php', '', 'menu-top menu-icon-tools', 'menu-update', 'div' ); 
     51if ( $update_data['counts']['total'] ) { 
     52    $menu[30] = 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>" ), 'manage_network', 'upgrade.php', '', 'menu-top menu-icon-tools', 'menu-update', 'div' ); 
    7353} else { 
    7454    $menu[30] = array( __( 'Updates' ), 'manage_network', 'upgrade.php', '', 'menu-top menu-icon-tools', 'menu-update', 'div' ); 
    7555} 
    7656 
     57unset($update_data); 
     58 
    7759$submenu[ 'upgrade.php' ][10] = array( __( 'Available Updates' ), 'update_core',  'update-core.php' ); 
    7860$submenu[ 'upgrade.php' ][15] = array( __( 'Update Network' ), 'manage_network', 'upgrade.php' ); 
    79 unset($plugin_update_count, $theme_update_count, $wordpress_update_count, $update_count, $update_title, $update_themes, $update_plugins, $update_wordpress); 
    80  
    8161 
    8262$menu[99] = array( '', 'read', 'separator-last', '', 'wp-menu-separator-last' ); 
  • trunk/wp-includes/admin-bar.php

    r18451 r18468  
    324324 */ 
    325325function wp_admin_bar_updates_menu( $wp_admin_bar ) { 
    326     if ( !current_user_can('install_plugins') ) 
    327         return; 
    328  
    329     $plugin_update_count = $theme_update_count = $wordpress_update_count = 0; 
    330     $update_plugins = get_site_transient( 'update_plugins' ); 
    331     if ( !empty($update_plugins->response) ) 
    332         $plugin_update_count = count( $update_plugins->response ); 
    333     $update_themes = get_site_transient( 'update_themes' ); 
    334     if ( !empty($update_themes->response) ) 
    335         $theme_update_count = count( $update_themes->response ); 
    336     /* @todo get_core_updates() is only available on admin page loads 
    337     $update_wordpress = get_core_updates( array('dismissed' => false) ); 
    338     if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) ) 
    339         $wordpress_update_count = 1; 
    340     */ 
    341  
    342     $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count; 
    343  
    344     if ( !$update_count ) 
    345         return; 
    346  
    347     $update_title = array(); 
    348     if ( $wordpress_update_count ) 
    349         $update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count); 
    350     if ( $plugin_update_count ) 
    351         $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count); 
    352     if ( $theme_update_count ) 
    353         $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $theme_update_count), $theme_update_count); 
    354  
    355     $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : ''; 
    356  
    357     $update_title = "<span title='$update_title'>"; 
    358     $update_title .= sprintf( __('Updates %s'), "<span id='ab-updates' class='update-count'>" . number_format_i18n($update_count) . '</span>' ); 
     326 
     327    $update_data = wp_get_update_data(); 
     328 
     329    if ( !$update_data['counts']['total'] ) 
     330        return; 
     331 
     332    $update_title = "<span title='{$update_data['title']}'>"; 
     333    $update_title .= sprintf( __('Updates %s'), "<span id='ab-updates' class='update-count'>" . number_format_i18n($update_data['counts']['total']) . '</span>' ); 
    359334    $update_title .= '</span>'; 
    360335 
  • trunk/wp-includes/update.php

    r18392 r18468  
    281281} 
    282282 
     283/* 
     284 * Collect counts and UI strings for available updates 
     285 * 
     286 * @since 3.3.0 
     287 * 
     288 * @return array 
     289 */ 
     290function wp_get_update_data() { 
     291    $counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0 ); 
     292 
     293    if ( current_user_can( 'update_plugins' ) ) { 
     294        $update_plugins = get_site_transient( 'update_plugins' ); 
     295        if ( ! empty( $update_plugins->response ) ) 
     296            $counts['plugins'] = count( $update_plugins->response ); 
     297    } 
     298 
     299    if ( current_user_can( 'update_themes' ) ) { 
     300        $update_themes = get_site_transient( 'update_themes' ); 
     301        if ( ! empty( $update_themes->response ) ) 
     302            $counts['themes'] = count( $update_themes->response ); 
     303    } 
     304 
     305    if ( function_exists( 'get_core_updates' ) && current_user_can( 'update_core' ) ) { 
     306        $update_wordpress = get_core_updates( array('dismissed' => false) ); 
     307        if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') ) 
     308            $counts['wordpress'] = 1; 
     309    } 
     310 
     311    $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress']; 
     312    $update_title = array(); 
     313    if ( $counts['wordpress'] ) 
     314        $update_title[] = sprintf(__('%d WordPress Update'), $counts['wordpress']); 
     315    if ( $counts['plugins'] ) 
     316        $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $counts['plugins']), $counts['plugins']); 
     317    if ( $counts['themes'] ) 
     318        $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $counts['themes']), $counts['themes']); 
     319 
     320    $update_title = ! empty( $update_title ) ? esc_attr( implode( ', ', $update_title ) ) : ''; 
     321     
     322    return array( 'counts' => $counts, 'title' => $update_title ); 
     323} 
     324 
    283325function _maybe_update_core() { 
    284326    include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version 
Note: See TracChangeset for help on using the changeset viewer.