WordPress.org

Make WordPress Core

Ticket #17694: 17694.3.diff

File 17694.3.diff, 13.1 KB (added by mitchoyoshitaka, 7 years ago)

Patch v3, merge with [18157]

  • wp-admin/network/menu.php

     
    2121$submenu['users.php'][5]  = array( __('All Users'), 'manage_network_users', 'users.php' );
    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' );
    3230}
     
    3533$submenu['themes.php'][15] = array( _x('Editor', 'theme editor'), 'edit_themes', 'theme-editor.php' );
    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' );
    4439}
     
    5348        $submenu['settings.php'][10] = array( __('Network Setup'), 'manage_network_options', 'setup.php' );
    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);
    8061
    81 
    8262$menu[99] = array( '', 'read', 'separator-last', '', 'wp-menu-separator-last' );
    8363
    8464require_once(ABSPATH . 'wp-admin/includes/menu.php');
  • wp-admin/menu.php

     
    3030        $submenu[ 'index.php' ][5] = array( __('My Sites'), 'read', 'my-sites.php' );
    3131}
    3232
    33 if ( ! is_multisite() || is_super_admin() ) {
    34         $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
     33if ( ! is_multisite() || is_super_admin() )
     34        $update_data = wp_get_update_data();
    3535
    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 }
    65 
    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');
     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');
    6838}
    6939
    70 unset($theme_update_count, $wordpress_update_count, $update_themes, $update_plugins, $update_wordpress);
    71 
    7240$menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
    7341
    7442$menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top menu-icon-post', 'menu-posts', 'div' );
     
    176144
    177145$menu_perms = get_site_option('menu_items', array());
    178146if ( ! is_multisite() || is_super_admin() || ! empty( $menu_perms['plugins'] ) ) {
    179         $count = "<span class='update-plugins count-$plugin_update_count'><span class='plugin-count'>" . number_format_i18n($plugin_update_count) . "</span></span>";
     147        if ( !isset( $update_data ) )
     148                $update_data = wp_get_update_data();
     149
     150        $count = "<span class='update-plugins count-{$update_data['counts']['plugins']}'><span class='plugin-count'>" . number_format_i18n($update_data['counts']['plugins']) . "</span></span>";
    180151        if ( is_multisite() || ! current_user_can( 'update_plugins' ) )
    181152                $count = '';
    182153        $menu[65] = array( sprintf( __('Plugins %s'), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' );
     
    189160                        $submenu['plugins.php'][15] = array( _x('Editor', 'plugin editor'), 'edit_plugins', 'plugin-editor.php' );
    190161                }
    191162}
    192 unset($menu_perms, $update_plugins, $plugin_update_count);
     163unset($menu_perms, $update_data);
    193164
    194165if ( current_user_can('list_users') )
    195166        $menu[70] = array( __('Users'), 'list_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' );
  • wp-includes/admin-bar.php

     
    264264 * @since 3.1.0
    265265 */
    266266function wp_admin_bar_updates_menu( $wp_admin_bar ) {
    267         if ( !current_user_can('install_plugins') )
    268                 return;
    269267
    270         $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
    271         $update_plugins = get_site_transient( 'update_plugins' );
    272         if ( !empty($update_plugins->response) )
    273                 $plugin_update_count = count( $update_plugins->response );
    274         $update_themes = get_site_transient( 'update_themes' );
    275         if ( !empty($update_themes->response) )
    276                 $theme_update_count = count( $update_themes->response );
    277         /* @todo get_core_updates() is only available on admin page loads
    278         $update_wordpress = get_core_updates( array('dismissed' => false) );
    279         if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) )
    280                 $wordpress_update_count = 1;
    281         */
     268        $update_data = wp_get_update_data();
    282269
    283         $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count;
    284 
    285         if ( !$update_count )
     270        if ( !$update_data['counts']['total'] )
    286271                return;
    287272
    288         $update_title = array();
    289         if ( $wordpress_update_count )
    290                 $update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count);
    291         if ( $plugin_update_count )
    292                 $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count);
    293         if ( $theme_update_count )
    294                 $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $theme_update_count), $theme_update_count);
    295 
    296         $update_title = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : '';
    297 
    298         $update_title = "<span title='$update_title'>";
    299         $update_title .= sprintf( __('Updates %s'), "<span id='ab-updates' class='update-count'>" . number_format_i18n($update_count) . '</span>' );
     273        $update_title = "<span title='{$update_data['title']}'>";
     274        $update_title .= sprintf( __('Updates %s'), "<span id='ab-updates' class='update-count'>" . number_format_i18n($update_data['counts']['total']) . '</span>' );
    300275        $update_title .= '</span>';
    301276
    302277        $wp_admin_bar->add_menu( array( 'id' => 'updates', 'title' => $update_title, 'href' => network_admin_url( 'update-core.php' ) ) );
  • wp-includes/update.php

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