From 01f0afcd21b140983fbaad8a1efc546b63e63b1f Mon Sep 17 00:00:00 2001 From: dd32 Date: Tue, 26 Jan 2010 06:53:47 +0000 Subject: [PATCH] First scratch at Bulk plugin upgrade from Plugins page. Props nacin for cleanups. See #11542 git-svn-id: http://svn.automattic.com/wordpress/trunk@12832 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/plugins.php | 47 ++++++++++++++++++++++++++++++++++++++++ wp-admin/update-core.php | 18 +++++++-------- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index a725b69ca2..aff423108c 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -83,6 +83,48 @@ if ( !empty($action) ) { wp_redirect("plugins.php?activate-multi=true&plugin_status=$status&paged=$page"); 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 ) ); + $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-footer.php' ); + exit; + break; case 'error_scrape': if ( ! current_user_can('activate_plugins') ) wp_die(__('You do not have sufficient permissions to activate plugins for this blog.')); @@ -281,6 +323,8 @@ if ( !empty($invalid) )

deactivated.') ?>

deactivated.'); ?>

+ +

@@ -500,6 +544,9 @@ function print_plugin_actions($context, $field_name = 'action' ) { + + + diff --git a/wp-admin/update-core.php b/wp-admin/update-core.php index a21b2d935d..50b278e7e7 100644 --- a/wp-admin/update-core.php +++ b/wp-admin/update-core.php @@ -351,21 +351,21 @@ function no_update_actions($actions) { } function do_plugin_upgrade() { - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; - - if ( isset($_GET['plugins']) ) { - $plugins = explode(',', $_GET['plugins']); - } elseif ( isset($_POST['checked']) ) { + if ( isset( $_GET['plugins'] ) ) { + $plugins = explode( ',', $_GET['plugins'] ); + } elseif ( isset( $_POST['checked'] ) ) { $plugins = (array) $_POST['checked']; } else { // Nothing to do. return; } - $url = 'update-core.php?action=do-plugin-upgrade&plugins=' . urlencode(join(',', $plugins)); - $title = __('Upgrade Plugins'); + + 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', 'plugin') ) ); - $upgrader->bulk_upgrade($plugins); + $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) ); + $upgrader->bulk_upgrade( $plugins ); } $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';