<!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>[16012] trunk/wp-admin: Don't call activation hooks when upgrading.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16012">16012</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-10-27 13:40:14 +0000 (Wed, 27 Oct 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Don't call activation hooks when upgrading. Props joelhardi for initial patch. See <a href="http://trac.wordpress.org/ticket/14915">#14915</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludespluginphp">trunk/wp-admin/includes/plugin.php</a></li>
<li><a href="#trunkwpadminupdatephp">trunk/wp-admin/update.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludespluginphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/plugin.php (16011 => 16012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/plugin.php        2010-10-27 13:20:53 UTC (rev 16011)
+++ trunk/wp-admin/includes/plugin.php        2010-10-27 13:40:14 UTC (rev 16012)
</span><span class="lines">@@ -460,10 +460,12 @@
</span><span class="cx">  *
</span><span class="cx">  * @param string $plugin Plugin path to main plugin file with plugin data.
</span><span class="cx">  * @param string $redirect Optional. URL to redirect to.
</span><del>- * @param bool $network_wide Whether to enable the plugin for all sites in the network or just the current site.  Multisite only. Default is false.
</del><ins>+ * @param bool $network_wide Whether to enable the plugin for all sites in the 
+ *   network or just the current site. Multisite only. Default is false.
+ * @param bool $silent Prevent calling activation hooks. Optional, default is false.
</ins><span class="cx">  * @return WP_Error|null WP_Error on invalid file or null on success.
</span><span class="cx">  */
</span><del>-function activate_plugin( $plugin, $redirect = '', $network_wide = false) {
</del><ins>+function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
</ins><span class="cx">         $plugin = plugin_basename( trim( $plugin ) );
</span><span class="cx"> 
</span><span class="cx">         if ( is_multisite() &amp;&amp; ( $network_wide || is_network_only_plugin($plugin) ) ) {
</span><span class="lines">@@ -482,8 +484,12 @@
</span><span class="cx">                         wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
</span><span class="cx">                 ob_start();
</span><span class="cx">                 include(WP_PLUGIN_DIR . '/' . $plugin);
</span><del>-                do_action( 'activate_plugin', $plugin, $network_wide );
-                do_action( 'activate_' . $plugin, $network_wide );
</del><ins>+
+                if ( ! $silent ) {
+                        do_action( 'activate_plugin', $plugin, $network_wide );
+                        do_action( 'activate_' . $plugin, $network_wide );
+                }
+
</ins><span class="cx">                 if ( $network_wide ) {
</span><span class="cx">                         $current[$plugin] = time();
</span><span class="cx">                         update_site_option( 'active_sitewide_plugins', $current );
</span><span class="lines">@@ -492,7 +498,11 @@
</span><span class="cx">                         sort($current);
</span><span class="cx">                         update_option('active_plugins', $current);
</span><span class="cx">                 }
</span><del>-                do_action( 'activated_plugin', $plugin, $network_wide );
</del><ins>+
+                if ( ! $silent ) {
+                        do_action( 'activated_plugin', $plugin, $network_wide );
+                }
+
</ins><span class="cx">                 if ( ob_get_length() &gt; 0 ) {
</span><span class="cx">                         $output = ob_get_clean();
</span><span class="cx">                         return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
</span><span class="lines">@@ -512,7 +522,7 @@
</span><span class="cx">  * @since unknown
</span><span class="cx">  *
</span><span class="cx">  * @param string|array $plugins Single plugin or list of plugins to deactivate.
</span><del>- * @param bool $silent Optional, default is false. Prevent calling deactivate hook.
</del><ins>+ * @param bool $silent Prevent calling deactivation hooks. Default is false.
</ins><span class="cx">  */
</span><span class="cx"> function deactivate_plugins( $plugins, $silent = false ) {
</span><span class="cx">         if ( is_multisite() )
</span><span class="lines">@@ -566,17 +576,18 @@
</span><span class="cx">  * @param string|array $plugins
</span><span class="cx">  * @param string $redirect Redirect to page after successful activation.
</span><span class="cx">  * @param bool $network_wide Whether to enable the plugin for all sites in the network.
</span><ins>+ * @param bool $silent Prevent calling activation hooks. Default is false.
</ins><span class="cx">  * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
</span><span class="cx">  */
</span><del>-function activate_plugins($plugins, $redirect = '', $network_wide) {
</del><ins>+function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) {
</ins><span class="cx">         if ( !is_array($plugins) )
</span><span class="cx">                 $plugins = array($plugins);
</span><span class="cx"> 
</span><span class="cx">         $errors = array();
</span><del>-        foreach ( (array) $plugins as $plugin ) {
</del><ins>+        foreach ( $plugins as $plugin ) {
</ins><span class="cx">                 if ( !empty($redirect) )
</span><span class="cx">                         $redirect = add_query_arg('plugin', $plugin, $redirect);
</span><del>-                $result = activate_plugin($plugin, $redirect, $network_wide);
</del><ins>+                $result = activate_plugin($plugin, $redirect, $network_wide, $silent);
</ins><span class="cx">                 if ( is_wp_error($result) )
</span><span class="cx">                         $errors[$plugin] = $result;
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkwpadminupdatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/update.php (16011 => 16012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/update.php        2010-10-27 13:20:53 UTC (rev 16011)
+++ trunk/wp-admin/update.php        2010-10-27 13:40:14 UTC (rev 16012)
</span><span class="lines">@@ -71,7 +71,7 @@
</span><span class="cx">                 check_admin_referer('activate-plugin_' . $plugin);
</span><span class="cx">                 if ( ! isset($_GET['failure']) &amp;&amp; ! isset($_GET['success']) ) {
</span><span class="cx">                         wp_redirect( admin_url('update.php?action=activate-plugin&amp;failure=true&amp;plugin=' . $plugin . '&amp;_wpnonce=' . $_GET['_wpnonce']) );
</span><del>-                        activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ) );
</del><ins>+                        activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true );
</ins><span class="cx">                         wp_redirect( admin_url('update.php?action=activate-plugin&amp;success=true&amp;plugin=' . $plugin . '&amp;_wpnonce=' . $_GET['_wpnonce']) );
</span><span class="cx">                         die();
</span><span class="cx">                 }
</span></span></pre>
</div>
</div>

</body>
</html>