Don't fetch update info our show update bubbles if the user does not have install caps. Props nacin. fixes #16532

git-svn-id: http://svn.automattic.com/wordpress/trunk@17822 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2011-05-06 19:48:13 +00:00
parent f824fbe47f
commit c39f85038e
2 changed files with 58 additions and 41 deletions

View File

@ -32,15 +32,24 @@ if ( is_multisite() ) {
if ( ! is_multisite() || is_super_admin() ) { if ( ! is_multisite() || is_super_admin() ) {
$plugin_update_count = $theme_update_count = $wordpress_update_count = 0; $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
if ( current_user_can( 'update_plugins' ) ) {
$update_plugins = get_site_transient( 'update_plugins' ); $update_plugins = get_site_transient( 'update_plugins' );
if ( !empty($update_plugins->response) && current_user_can('update_plugins') ) if ( ! empty( $update_plugins->response ) )
$plugin_update_count = count( $update_plugins->response ); $plugin_update_count = count( $update_plugins->response );
}
if ( current_user_can( 'update_themes' ) ) {
$update_themes = get_site_transient( 'update_themes' ); $update_themes = get_site_transient( 'update_themes' );
if ( !empty($update_themes->response) && current_user_can('update_themes') ) if ( !empty($update_themes->response) )
$theme_update_count = count( $update_themes->response ); $theme_update_count = count( $update_themes->response );
}
if ( current_user_can( 'update_core' ) ) {
$update_wordpress = get_core_updates( array('dismissed' => false) ); $update_wordpress = get_core_updates( array('dismissed' => false) );
if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') ) if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') )
$wordpress_update_count = 1; $wordpress_update_count = 1;
}
$total_update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count; $total_update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count;
$update_title = array(); $update_title = array();
@ -58,7 +67,7 @@ if ( ! is_multisite() ) {
$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'); $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');
} }
unset($plugin_update_count, $theme_update_count, $wordpress_update_count, $update_themes, $update_plugins, $update_wordpress); unset($theme_update_count, $wordpress_update_count, $update_themes, $update_plugins, $update_wordpress);
$menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' ); $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
@ -163,14 +172,9 @@ function _add_themes_utility_last() {
add_submenu_page('themes.php', _x('Editor', 'theme editor'), _x('Editor', 'theme editor'), 'edit_themes', 'theme-editor.php'); add_submenu_page('themes.php', _x('Editor', 'theme editor'), _x('Editor', 'theme editor'), 'edit_themes', 'theme-editor.php');
} }
$update_plugins = get_site_transient( 'update_plugins' );
$update_count = 0;
if ( !empty($update_plugins->response) )
$update_count = count( $update_plugins->response );
$menu_perms = get_site_option('menu_items', array()); $menu_perms = get_site_option('menu_items', array());
if ( ! is_multisite() || is_super_admin() || ! empty( $menu_perms['plugins'] ) ) { if ( ! is_multisite() || is_super_admin() || ! empty( $menu_perms['plugins'] ) ) {
$count = "<span class='update-plugins count-$update_count'><span class='plugin-count'>" . number_format_i18n($update_count) . "</span></span>"; $count = "<span class='update-plugins count-$plugin_update_count'><span class='plugin-count'>" . number_format_i18n($plugin_update_count) . "</span></span>";
if ( is_multisite() || ! current_user_can( 'update_plugins' ) ) if ( is_multisite() || ! current_user_can( 'update_plugins' ) )
$count = ''; $count = '';
$menu[65] = array( sprintf( __('Plugins %s'), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' ); $menu[65] = array( sprintf( __('Plugins %s'), $count ), 'activate_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' );
@ -181,7 +185,7 @@ if ( ! is_multisite() || is_super_admin() || ! empty( $menu_perms['plugins'] ) )
$submenu['plugins.php'][15] = array( _x('Editor', 'plugin editor'), 'edit_plugins', 'plugin-editor.php' ); $submenu['plugins.php'][15] = array( _x('Editor', 'plugin editor'), 'edit_plugins', 'plugin-editor.php' );
} }
} }
unset($menu_perms, $update_plugins, $update_count); unset($menu_perms, $update_plugins, $plugin_update_count);
if ( current_user_can('list_users') ) if ( current_user_can('list_users') )
$menu[70] = array( __('Users'), 'list_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' ); $menu[70] = array( __('Users'), 'list_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'div' );

View File

@ -21,19 +21,27 @@ $menu[10] = array(__('Users'), 'manage_network_users', 'users.php', '', 'menu-to
$submenu['users.php'][5] = array( __('Users'), 'manage_network_users', 'users.php' ); $submenu['users.php'][5] = array( __('Users'), 'manage_network_users', 'users.php' );
$submenu['users.php'][10] = array( _x('Add New', 'user'), 'create_users', 'user-new.php' ); $submenu['users.php'][10] = array( _x('Add New', 'user'), 'create_users', 'user-new.php' );
$plugin_update_count = $theme_update_count = $wordpress_update_count = 0; if ( current_user_can( 'update_themes' ) ) {
$update_themes = get_site_transient( 'update_themes' ); $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
if ( !empty($update_themes->response) ) $update_themes = get_site_transient( 'update_themes' );
if ( !empty($update_themes->response) )
$theme_update_count = count( $update_themes->response ); $theme_update_count = count( $update_themes->response );
$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'); $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' );
} else {
$menu[15] = array( __( 'Themes' ), 'manage_network_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div' );
}
$submenu['themes.php'][5] = array( __('Themes'), 'manage_network_themes', 'themes.php' ); $submenu['themes.php'][5] = array( __('Themes'), 'manage_network_themes', 'themes.php' );
$submenu['themes.php'][10] = array( _x('Add New', 'theme'), 'install_themes', 'theme-install.php' ); $submenu['themes.php'][10] = array( _x('Add New', 'theme'), 'install_themes', 'theme-install.php' );
$submenu['themes.php'][15] = array( _x('Editor', 'theme editor'), 'edit_themes', 'theme-editor.php' ); $submenu['themes.php'][15] = array( _x('Editor', 'theme editor'), 'edit_themes', 'theme-editor.php' );
$update_plugins = get_site_transient( 'update_plugins' ); if ( current_user_can( 'update_plugins' ) ) {
if ( !empty($update_plugins->response) ) $update_plugins = get_site_transient( 'update_plugins' );
if ( !empty($update_plugins->response) )
$plugin_update_count = count( $update_plugins->response ); $plugin_update_count = count( $update_plugins->response );
$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'); $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');
} else {
$menu[20] = array( __('Plugins'), 'manage_network_plugins', 'plugins.php', '', 'menu-top menu-icon-plugins', 'menu-plugins', 'div' );
}
$submenu['plugins.php'][5] = array( __('Plugins'), 'manage_network_plugins', 'plugins.php' ); $submenu['plugins.php'][5] = array( __('Plugins'), 'manage_network_plugins', 'plugins.php' );
$submenu['plugins.php'][10] = array( _x('Add New', 'plugin editor'), 'install_plugins', 'plugin-install.php' ); $submenu['plugins.php'][10] = array( _x('Add New', 'plugin editor'), 'install_plugins', 'plugin-install.php' );
$submenu['plugins.php'][15] = array( _x('Editor', 'plugin editor'), 'edit_plugins', 'plugin-editor.php' ); $submenu['plugins.php'][15] = array( _x('Editor', 'plugin editor'), 'edit_plugins', 'plugin-editor.php' );
@ -45,22 +53,27 @@ if ( defined( 'MULTISITE' ) && defined( 'WP_ALLOW_MULTISITE' ) && WP_ALLOW_MULTI
$submenu['settings.php'][10] = array( __('Network Setup'), 'manage_network_options', 'setup.php' ); $submenu['settings.php'][10] = array( __('Network Setup'), 'manage_network_options', 'setup.php' );
} }
$update_wordpress = get_core_updates( array('dismissed' => false) ); if ( current_user_can( 'update_core' ) ) {
if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) ) $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; $wordpress_update_count = 1;
$update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count; $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count;
$update_title = array(); $update_title = array();
if ( $wordpress_update_count ) if ( $wordpress_update_count )
$update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count); $update_title[] = sprintf(__('%d WordPress Update'), $wordpress_update_count);
if ( $plugin_update_count ) if ( $plugin_update_count )
$update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count); $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $plugin_update_count), $plugin_update_count);
if ( $theme_update_count ) if ( $theme_update_count )
$update_title[] = sprintf(_n('%d Theme Update', '%d Themes Updates', $theme_update_count), $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 = !empty($update_title) ? esc_attr(implode(', ', $update_title)) : '';
$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' );
} else {
$menu[30] = array( __( 'Updates' ), 'manage_network', 'upgrade.php', '', 'menu-top menu-icon-tools', 'menu-update', 'div' );
}
$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');
$submenu[ 'upgrade.php' ][10] = array( __( 'Updates' ), 'update_core', 'update-core.php' ); $submenu[ 'upgrade.php' ][10] = array( __( 'Updates' ), 'update_core', 'update-core.php' );
$submenu[ 'upgrade.php' ][15] = array( __( 'Update Network' ), 'manage_network', 'upgrade.php' ); $submenu[ 'upgrade.php' ][15] = array( __( 'Update Network' ), 'manage_network', 'upgrade.php' );
unset($plugin_update_count, $theme_update_count, $wordpress_update_count, $update_count, $update_title, $update_themes, $update_plugins, $update_wordpress); unset($plugin_update_count, $theme_update_count, $wordpress_update_count, $update_count, $update_title, $update_themes, $update_plugins, $update_wordpress);