<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12832] trunk/wp-admin:
First scratch at Bulk plugin upgrade from Plugins page.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12832">12832</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-01-26 06:53:47 +0000 (Tue, 26 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>First scratch at Bulk plugin upgrade from Plugins page. Props nacin for cleanups. See <a href="http://trac.wordpress.org/ticket/11542">#11542</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminpluginsphp">trunk/wp-admin/plugins.php</a></li>
<li><a href="#trunkwpadminupdatecorephp">trunk/wp-admin/update-core.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminpluginsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/plugins.php (12831 => 12832)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/plugins.php        2010-01-26 06:06:14 UTC (rev 12831)
+++ trunk/wp-admin/plugins.php        2010-01-26 06:53:47 UTC (rev 12832)
</span><span class="lines">@@ -83,6 +83,48 @@
</span><span class="cx">                         wp_redirect("plugins.php?activate-multi=true&plugin_status=$status&paged=$page");
</span><span class="cx">                         exit;
</span><span class="cx">                         break;
</span><ins>+                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&amp;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;
</ins><span class="cx">                 case 'error_scrape':
</span><span class="cx">                         if ( ! current_user_can('activate_plugins') )
</span><span class="cx">                                 wp_die(__('You do not have sufficient permissions to activate plugins for this blog.'));
</span><span class="lines">@@ -281,6 +323,8 @@
</span><span class="cx">         <div id="message" class="updated"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
</span><span class="cx"> <?php elseif (isset($_GET['deactivate-multi'])) : ?>
</span><span class="cx">         <div id="message" class="updated"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div>
</span><ins>+<?php elseif ( 'update-selected' == $action ) : ?>
+        <div id="message" class="updated"><p><?php _e('No out of date plugins were selected.'); ?></p></div>
</ins><span class="cx"> <?php endif; ?>
</span><span class="cx">
</span><span class="cx"> <div class="wrap">
</span><span class="lines">@@ -500,6 +544,9 @@
</span><span class="cx">         <?php if ( 'inactive' != $context && 'recent' != $context ) : ?>
</span><span class="cx">                         <option value="deactivate-selected"><?php _e('Deactivate'); ?></option>
</span><span class="cx">         <?php endif; ?>
</span><ins>+        <?php if ( current_user_can( 'update_plugins' ) ) : ?>
+                        <option value="update-selected"><?php _e( 'Upgrade' ); ?></option>
+        <?php endif; ?>
</ins><span class="cx">         <?php if ( current_user_can('delete_plugins') && ( 'active' != $context ) ) : ?>
</span><span class="cx">                         <option value="delete-selected"><?php _e('Delete'); ?></option>
</span><span class="cx">         <?php endif; ?>
</span></span></pre></div>
<a id="trunkwpadminupdatecorephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/update-core.php (12831 => 12832)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/update-core.php        2010-01-26 06:06:14 UTC (rev 12831)
+++ trunk/wp-admin/update-core.php        2010-01-26 06:53:47 UTC (rev 12832)
</span><span class="lines">@@ -351,21 +351,21 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function do_plugin_upgrade() {
</span><del>-        include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
-
-        if ( isset($_GET['plugins']) ) {
-                $plugins = explode(',', $_GET['plugins']);
-        } elseif ( isset($_POST['checked']) ) {
</del><ins>+        if ( isset( $_GET['plugins'] ) ) {
+                $plugins = explode( ',', $_GET['plugins'] );
+        } elseif ( isset( $_POST['checked'] ) ) {
</ins><span class="cx">                 $plugins = (array) $_POST['checked'];
</span><span class="cx">         } else {
</span><span class="cx">                 // Nothing to do.
</span><span class="cx">                 return;
</span><span class="cx">         }
</span><del>-        $url = 'update-core.php?action=do-plugin-upgrade&amp;plugins=' . urlencode(join(',', $plugins));
-        $title = __('Upgrade Plugins');
</del><ins>+
+        include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
+        $url = 'update-core.php?action=do-plugin-upgrade&amp;plugins=' . urlencode( implode( ',', $plugins ) );
+        $title = __( 'Upgrade Plugins' );
</ins><span class="cx">         $nonce = 'upgrade-core';
</span><del>-        $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
-        $upgrader->bulk_upgrade($plugins);
</del><ins>+        $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) );
+        $upgrader->bulk_upgrade( $plugins );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
</span></span></pre>
</div>
</div>
</body>
</html>