From 4ff21e0cd39aabaaf84f8328f54ca1ad86bbf585 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 23 Oct 2009 21:49:12 +0000 Subject: [PATCH] Plugin bulk upgrade rough in. see #10973 git-svn-id: http://svn.automattic.com/wordpress/trunk@12097 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-upgrader.php | 60 +++++++++++++++++++++++++ wp-admin/update-core.php | 21 ++++++--- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 9d707b6721..048d58cf6d 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -354,6 +354,7 @@ class WP_Upgrader { class Plugin_Upgrader extends WP_Upgrader { var $result; + var $bulk = true; function upgrade_strings() { $this->strings['up_to_date'] = __('The plugin is at the latest version.'); @@ -435,6 +436,58 @@ class Plugin_Upgrader extends WP_Upgrader { delete_transient('update_plugins'); } + function bulk_upgrade($plugins) { + + $this->init(); + $this->bulk = true; + $this->upgrade_strings(); + + $current = get_transient( 'update_plugins' ); + + add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2); + add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); + + foreach ( $plugins as $plugin ) { + if ( !isset( $current->response[ $plugin ] ) ) { + $this->skin->set_result(false); + $this->skin->error('up_to_date'); + $this->skin->after(); + $results[$plugin] = false; + continue; + } + + // Get the URL to the zip file + $r = $current->response[ $plugin ]; + + $this->skin->plugin_active = is_plugin_active($plugin); + + $result = $this->run(array( + 'package' => $r->package, + 'destination' => WP_PLUGIN_DIR, + 'clear_destination' => true, + 'clear_working' => true, + 'hook_extra' => array( + 'plugin' => $plugin + ) + )); + + $results[$plugin] = $this->result; + + // Prevent credentials auth screen from displaying multiple times + if ( false === $result ) + break; + } + + //Cleanup our hooks, incase something else does a upgrade on this connection. + remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade')); + remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); + + // Force refresh of plugin update information + delete_transient('update_plugins'); + + return $results; + } + //return plugin info. function plugin_info() { if ( ! is_array($this->result) ) @@ -848,6 +901,13 @@ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { if ( ! empty($update_actions) ) $this->feedback('' . __('Actions:') . ' ' . implode(' | ', (array)$update_actions)); } + + function footer() { + if ( $this->upgrader->bulk ) + return; + + echo ''; + } } /** diff --git a/wp-admin/update-core.php b/wp-admin/update-core.php index ff2d7d57c9..57cec56a92 100644 --- a/wp-admin/update-core.php +++ b/wp-admin/update-core.php @@ -285,16 +285,25 @@ function do_undismiss_core_update() { wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') ); } +function no_update_actions($actions) { + return ''; +} + function do_plugin_upgrade() { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; - $plugins = (array) $_POST['checked']; - $url = 'update-core.php'; - - foreach ( $plugins as $plugin ) { - $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) ); - $upgrader->upgrade($plugin); + if ( isset($_GET['plugins']) ) { + $plugins = explode(',', $_GET['plugins']); + } else { + $plugins = (array) $_POST['checked']; } + $url = 'update-core.php?action=do-plugin-upgrade&plugins=' . urlencode(join(',', $plugins)); + $title = __('Upgrade Plugins'); + $nonce = 'upgrade-core'; + add_filter('update_plugin_complete_actions', 'no_update_actions'); + + $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) ); + $upgrader->bulk_upgrade($plugins); } $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';