diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 708577e77..1ecd0e0a5 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -297,6 +297,7 @@ class WP_Upgrader { $download = $this->download_package( $package ); if ( is_wp_error($download) ) { $this->skin->error($download); + $this->skin->after(); return $download; } @@ -304,6 +305,7 @@ class WP_Upgrader { $working_dir = $this->unpack_package( $download ); if ( is_wp_error($working_dir) ) { $this->skin->error($working_dir); + $this->skin->after(); return $working_dir; } @@ -409,6 +411,7 @@ class Plugin_Upgrader extends WP_Upgrader { $current = get_site_transient( 'update_plugins' ); if ( !isset( $current->response[ $plugin ] ) ) { + $this->skin->before(); $this->skin->set_result(false); $this->skin->error('up_to_date'); $this->skin->after(); @@ -466,15 +469,15 @@ class Plugin_Upgrader extends WP_Upgrader { $results = array(); - $all = count($plugins); - $i = 1; + $this->plugin_count = count($plugins); + $this->plugin_current = 0; foreach ( $plugins as $plugin ) { - - $this->show_before = sprintf( '

' . __('Updating plugin %1$d of %2$d…') . '

', $i, $all ); - $i++; + $this->plugin_current++; + $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true); if ( !isset( $current->response[ $plugin ] ) ) { $this->skin->set_result(false); + $this->skin->before(); $this->skin->error('up_to_date'); $this->skin->after(); $results[$plugin] = false; @@ -502,7 +505,7 @@ class Plugin_Upgrader extends WP_Upgrader { // Prevent credentials auth screen from displaying multiple times if ( false === $result ) break; - } + } //end foreach $plugins $this->maintenance_mode(false); $this->skin->footer(); @@ -645,6 +648,7 @@ class Theme_Upgrader extends WP_Upgrader { // Is an update available? $current = get_site_transient( 'update_themes' ); if ( !isset( $current->response[ $theme ] ) ) { + $this->skin->before(); $this->skin->set_result(false); $this->skin->error('up_to_date'); $this->skin->after(); @@ -910,9 +914,6 @@ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { } function after() { - if ( $this->upgrader->bulk ) - return; - $this->plugin = $this->upgrader->plugin_info(); if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){ show_message(__('Reactivating the plugin…')); @@ -941,6 +942,103 @@ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { } } +/** + * Plugin Upgrader Skin for WordPress Plugin Upgrades. + * + * @package WordPress + * @subpackage Upgrader + * @since 3.0 + */ +class Bulk_Plugin_Upgrader_Skin extends WP_Upgrader_Skin { + var $in_loop = false; + var $error = false; + + function Plugin_Upgrader_Skin($args = array()) { + return $this->__construct($args); + } + + function __construct($args = array()) { + $defaults = array( 'url' => '', 'nonce' => '' ); + $args = wp_parse_args($args, $defaults); + + parent::__construct($args); + } + + function feedback($string) { + if ( isset( $this->upgrader->strings[$string] ) ) + $string = $this->upgrader->strings[$string]; + + if ( strpos($string, '%') !== false ) { + $args = func_get_args(); + $args = array_splice($args, 1); + if ( !empty($args) ) + $string = vsprintf($string, $args); + } + if ( empty($string) ) + return; + if ( $this->in_loop ) + echo "$string
\n"; + else + echo "

$string

\n"; + } + + function header() { + // Nothing, This will be displayed within a iframe. + } + + function footer() { + // Nothing, This will be displayed within a iframe. + } + function error($error) { + if ( is_string($error) && isset( $this->upgrader->strings[$error] ) ) + $this->error = $this->upgrader->strings[$error]; + + if ( is_wp_error($error) && $error->get_error_code() ) { + foreach ( $error->get_error_messages() as $emessage ) { + if ( $error->get_error_data() ) + $messages[] = $emessage . ' ' . $error->get_error_data(); + else + $messages[] = $emessage; + } + $this->error = implode(', ', $messages); + } + } + + function before() { + $this->in_loop = true; + printf( '

' . __('Updating Plugin %1$s (%2$d/%3$d)') . '

', $this->plugin_info['Title'], $this->upgrader->plugin_current, $this->upgrader->plugin_count); + echo ''; + if ( $this->error || ! $this->result ) { + if ( $this->error ) + echo '

' . sprintf(__('An error occured while updating %1$s: %2$s.'), $this->plugin_info['Title'], $this->error) . '

'; + else + echo '

' . sprintf(__('The update of %1$s failed.'), $this->plugin_info['Title']) . '

'; + echo ''; + } + if ( !empty($this->result) && !is_wp_error($this->result) ) { + echo '

' . sprintf(__('%1$s updated successfully. See Details.'), $this->plugin_info['Title'], 'jQuery(\'#progress-' . esc_js($this->upgrader->plugin_current) . '\').toggle(); return false;') . '

'; + } + $this->reset(); + $this->flush_output(); + } + + function reset() { + $this->in_loop = false; + $this->error = false; + } + + function flush_output() { + wp_ob_end_flush_all(); + flush(); + } + +} + /** * Plugin Installer Skin for WordPress Plugin Installer. * diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index 942a9e146..0e6a07275 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -271,6 +271,8 @@ function show_message($message) { $message = $message->get_error_message(); } echo "

$message

\n"; + wp_ob_end_flush_all(); + flush(); } function wp_doc_link_parse( $content ) { diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index a2cc31d41..9f0623908 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -96,44 +96,31 @@ if ( !empty($action) ) { exit; break; case 'update-selected' : - if ( ! current_user_can( 'update_plugins' ) ) - wp_die( __( 'You do not have sufficient permissions to update plugins for this blog.' ) ); - + check_admin_referer( 'bulk-manage-plugins' ); - + if ( isset( $_GET['plugins'] ) ) $plugins = explode( ',', $_GET['plugins'] ); elseif ( isset( $_POST['checked'] ) ) $plugins = (array) $_POST['checked']; else - break; - - if ( empty( $plugins ) ) - break; - - // We'll be passing all checked plugins as long as at least one is out of date. - $_plugins = $plugins; - $current = get_site_transient( 'update_plugins' ); - foreach ( $_plugins as $k => $v ) { - if ( ! isset( $current->response[ $v ] ) ) - unset( $_plugins[ $k ] ); - } - unset( $current ); - // If all checked plugins are up to date - if ( empty( $_plugins ) ) - break; - - require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); - require_once( 'admin-header.php' ); - - $url = 'plugins.php?action=upgrade-selected&plugins=' . urlencode( join( ',', $plugins ) ); + $plugins = array(); + $title = __( 'Upgrade Plugins' ); - $nonce = 'bulk-manage-plugins'; $parent_file = 'plugins.php'; - $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) ); - $upgrader->bulk_upgrade( $plugins ); + require_once( 'admin-header.php' ); + + echo '
'; + screen_icon(); + echo '

' . esc_html( $title ) . '

'; + + $url = 'update.php?action=update-selected&plugins=' . urlencode( join(',', $plugins) ); + $url = wp_nonce_url($url, 'bulk-update-plugins'); + + echo ""; + echo '
'; require_once( 'admin-footer.php' ); exit; break; diff --git a/wp-admin/update-core.php b/wp-admin/update-core.php index b6cd2416b..0dca9873d 100644 --- a/wp-admin/update-core.php +++ b/wp-admin/update-core.php @@ -351,24 +351,6 @@ function no_update_actions($actions) { return ''; } -function do_plugin_upgrade() { - if ( isset( $_GET['plugins'] ) ) { - $plugins = explode( ',', $_GET['plugins'] ); - } elseif ( isset( $_POST['checked'] ) ) { - $plugins = (array) $_POST['checked']; - } else { - // Nothing to do. - return; - } - - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; - $url = 'update-core.php?action=do-plugin-upgrade&plugins=' . urlencode( implode( ',', $plugins ) ); - $title = __( 'Upgrade Plugins' ); - $nonce = 'upgrade-core'; - $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) ); - $upgrader->bulk_upgrade( $plugins ); -} - $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core'; $upgrade_error = false; @@ -386,23 +368,46 @@ if ( 'upgrade-core' == $action ) { core_upgrade_preamble(); } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) { check_admin_referer('upgrade-core'); + // do the (un)dismiss actions before headers, // so that they can redirect if ( isset( $_POST['dismiss'] ) ) do_dismiss_core_update(); elseif ( isset( $_POST['undismiss'] ) ) - do_undismiss_core_update(); + do_undismiss_core_update(); + require_once('admin-header.php'); if ( 'do-core-reinstall' == $action ) $reinstall = true; else $reinstall = false; + if ( isset( $_POST['upgrade'] ) ) do_core_upgrade($reinstall); + } elseif ( 'do-plugin-upgrade' == $action ) { check_admin_referer('upgrade-core'); + + if ( isset( $_GET['plugins'] ) ) { + $plugins = explode( ',', $_GET['plugins'] ); + } elseif ( isset( $_POST['checked'] ) ) { + $plugins = (array) $_POST['checked']; + } else { + wp_redirect('plugins.php'); + exit; + } + + $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins)); + $url = wp_nonce_url($url, 'bulk-update-plugins'); + + $title = __('Update Plugins'); + require_once('admin-header.php'); - do_plugin_upgrade(); + echo '
'; + screen_icon('plugins'); + echo '

' . esc_html__('Update Plugins') . '

'; + echo ""; + echo '
'; } include('admin-footer.php'); diff --git a/wp-admin/update.php b/wp-admin/update.php index 1a890531e..667c11bc0 100644 --- a/wp-admin/update.php +++ b/wp-admin/update.php @@ -16,7 +16,35 @@ if ( isset($_GET['action']) ) { $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : ''; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; - if ( 'upgrade-plugin' == $action ) { + if ( 'update-selected' == $action ) { + if ( ! current_user_can( 'update_plugins' ) ) + wp_die( __( 'You do not have sufficient permissions to update plugins for this blog.' ) ); + + check_admin_referer( 'bulk-update-plugins' ); + + if ( isset( $_GET['plugins'] ) ) + $plugins = explode( ',', stripslashes($_GET['plugins']) ); + elseif ( isset( $_POST['checked'] ) ) + $plugins = (array) $_POST['checked']; + else + $plugins = array(); + + $plugins = array_map('urldecode', $plugins); + + $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins)); + $nonce = 'bulk-update-plugins'; + + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); + wp_enqueue_script('jquery'); + iframe_header(); + + $upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); + $upgrader->bulk_upgrade( $plugins ); + + iframe_footer(); + exit; + + } elseif ( 'upgrade-plugin' == $action ) { if ( ! current_user_can('update_plugins') ) wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));