<!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" />
<title>[25272] trunk/src: Upgrader: Make clearing the Plugin and Theme update caches optional during install and upgrade proceedures.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/25272">25272</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2013-09-06 01:32:09 +0000 (Fri, 06 Sep 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Upgrader: Make clearing the Plugin and Theme update caches optional during install and upgrade proceedures. See <a href="http://core.trac.wordpress.org/ticket/22704">#22704</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesclasswpupgraderphp">trunk/src/wp-admin/includes/class-wp-upgrader.php</a></li>
<li><a href="#trunksrcwpadminincludespluginphp">trunk/src/wp-admin/includes/plugin.php</a></li>
<li><a href="#trunksrcwpincludesthemephp">trunk/src/wp-includes/theme.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesclasswpupgraderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader.php (25271 => 25272)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader.php 2013-09-06 01:20:17 UTC (rev 25271)
+++ trunk/src/wp-admin/includes/class-wp-upgrader.php 2013-09-06 01:32:09 UTC (rev 25272)
</span><span class="lines">@@ -163,13 +163,17 @@
</span><span class="cx"> return $working_dir;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function install_package($args = array()) {
</del><ins>+ function install_package( $args = array() ) {
</ins><span class="cx"> global $wp_filesystem, $wp_theme_directories;
</span><span class="cx">
</span><del>- $defaults = array( 'source' => '', 'destination' => '', //Please always pass these
- 'clear_destination' => false, 'clear_working' => false,
- 'abort_if_destination_exists' => true,
- 'hook_extra' => array());
</del><ins>+ $defaults = array(
+ 'source' => '', // Please always pass this
+ 'destination' => '', // and this
+ 'clear_destination' => false,
+ 'clear_working' => false,
+ 'abort_if_destination_exists' => true,
+ 'hook_extra' => array()
+ );
</ins><span class="cx">
</span><span class="cx"> $args = wp_parse_args($args, $defaults);
</span><span class="cx"> extract($args);
</span><span class="lines">@@ -277,14 +281,15 @@
</span><span class="cx">
</span><span class="cx"> function run($options) {
</span><span class="cx">
</span><del>- $defaults = array( 'package' => '', //Please always pass this.
- 'destination' => '', //And this
- 'clear_destination' => false,
- 'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please
- 'clear_working' => true,
- 'is_multi' => false,
- 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters.
- );
</del><ins>+ $defaults = array(
+ 'package' => '', // Please always pass this.
+ 'destination' => '', // And this
+ 'clear_destination' => false,
+ 'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please
+ 'clear_working' => true,
+ 'is_multi' => false,
+ 'hook_extra' => array() // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
+ );
</ins><span class="cx">
</span><span class="cx"> $options = wp_parse_args($options, $defaults);
</span><span class="cx"> extract($options);
</span><span class="lines">@@ -324,13 +329,14 @@
</span><span class="cx">
</span><span class="cx"> //With the given options, this installs it to the destination directory.
</span><span class="cx"> $result = $this->install_package( array(
</span><del>- 'source' => $working_dir,
- 'destination' => $destination,
- 'clear_destination' => $clear_destination,
- 'abort_if_destination_exists' => $abort_if_destination_exists,
- 'clear_working' => $clear_working,
- 'hook_extra' => $hook_extra
- ) );
</del><ins>+ 'source' => $working_dir,
+ 'destination' => $destination,
+ 'clear_destination' => $clear_destination,
+ 'abort_if_destination_exists' => $abort_if_destination_exists,
+ 'clear_working' => $clear_working,
+ 'hook_extra' => $hook_extra
+ ) );
+
</ins><span class="cx"> $this->skin->set_result($result);
</span><span class="cx"> if ( is_wp_error($result) ) {
</span><span class="cx"> $this->skin->error($result);
</span><span class="lines">@@ -398,20 +404,25 @@
</span><span class="cx"> $this->strings['process_success'] = __('Plugin installed successfully.');
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function install($package) {
</del><ins>+ function install( $package, $args = array() ) {
</ins><span class="cx">
</span><ins>+ $defaults = array(
+ 'clear_update_cache' => true,
+ );
+ $parsed_args = wp_parse_args( $defaults, $args );
+
</ins><span class="cx"> $this->init();
</span><span class="cx"> $this->install_strings();
</span><span class="cx">
</span><span class="cx"> add_filter('upgrader_source_selection', array($this, 'check_package') );
</span><span class="cx">
</span><del>- $this->run(array(
- 'package' => $package,
- 'destination' => WP_PLUGIN_DIR,
- 'clear_destination' => false, //Do not overwrite files.
- 'clear_working' => true,
- 'hook_extra' => array()
- ));
</del><ins>+ $this->run( array(
+ 'package' => $package,
+ 'destination' => WP_PLUGIN_DIR,
+ 'clear_destination' => false, // Do not overwrite files.
+ 'clear_working' => true,
+ 'hook_extra' => array()
+ ) );
</ins><span class="cx">
</span><span class="cx"> remove_filter('upgrader_source_selection', array($this, 'check_package') );
</span><span class="cx">
</span><span class="lines">@@ -419,15 +430,20 @@
</span><span class="cx"> return $this->result;
</span><span class="cx">
</span><span class="cx"> // Force refresh of plugin update information
</span><del>- delete_site_transient('update_plugins');
- wp_cache_delete( 'plugins', 'plugins' );
</del><ins>+ wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
+
</ins><span class="cx"> do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'plugin' ), $package );
</span><span class="cx">
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function upgrade($plugin) {
</del><ins>+ function upgrade( $plugin, $args = array() ) {
</ins><span class="cx">
</span><ins>+ $defaults = array(
+ 'clear_update_cache' => true,
+ );
+ $parsed_args = wp_parse_args( $defaults, $args );
+
</ins><span class="cx"> $this->init();
</span><span class="cx"> $this->upgrade_strings();
</span><span class="cx">
</span><span class="lines">@@ -447,15 +463,15 @@
</span><span class="cx"> add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4);
</span><span class="cx"> //'source_selection' => array($this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
</span><span class="cx">
</span><del>- $this->run(array(
- 'package' => $r->package,
- 'destination' => WP_PLUGIN_DIR,
- 'clear_destination' => true,
- 'clear_working' => true,
- 'hook_extra' => array(
- 'plugin' => $plugin
- )
- ));
</del><ins>+ $this->run( array(
+ 'package' => $r->package,
+ 'destination' => WP_PLUGIN_DIR,
+ 'clear_destination' => true,
+ 'clear_working' => true,
+ 'hook_extra' => array(
+ 'plugin' => $plugin
+ ),
+ ) );
</ins><span class="cx">
</span><span class="cx"> // Cleanup our hooks, in case something else does a upgrade on this connection.
</span><span class="cx"> remove_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'));
</span><span class="lines">@@ -465,15 +481,20 @@
</span><span class="cx"> return $this->result;
</span><span class="cx">
</span><span class="cx"> // Force refresh of plugin update information
</span><del>- delete_site_transient('update_plugins');
- wp_cache_delete( 'plugins', 'plugins' );
</del><ins>+ wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
+
</ins><span class="cx"> do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin' ), $plugin );
</span><span class="cx">
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function bulk_upgrade($plugins) {
</del><ins>+ function bulk_upgrade( $plugins, $args = array() ) {
</ins><span class="cx">
</span><ins>+ $defaults = array(
+ 'clear_update_cache' => true,
+ );
+ $parsed_args = wp_parse_args( $defaults, $args );
+
</ins><span class="cx"> $this->init();
</span><span class="cx"> $this->bulk = true;
</span><span class="cx"> $this->upgrade_strings();
</span><span class="lines">@@ -525,16 +546,16 @@
</span><span class="cx">
</span><span class="cx"> $this->skin->plugin_active = is_plugin_active($plugin);
</span><span class="cx">
</span><del>- $result = $this->run(array(
- 'package' => $r->package,
- 'destination' => WP_PLUGIN_DIR,
- 'clear_destination' => true,
- 'clear_working' => true,
- 'is_multi' => true,
- 'hook_extra' => array(
- 'plugin' => $plugin
- )
- ));
</del><ins>+ $result = $this->run( array(
+ 'package' => $r->package,
+ 'destination' => WP_PLUGIN_DIR,
+ 'clear_destination' => true,
+ 'clear_working' => true,
+ 'is_multi' => true,
+ 'hook_extra' => array(
+ 'plugin' => $plugin
+ )
+ ) );
</ins><span class="cx">
</span><span class="cx"> $results[$plugin] = $this->result;
</span><span class="cx">
</span><span class="lines">@@ -553,8 +574,8 @@
</span><span class="cx"> remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'));
</span><span class="cx">
</span><span class="cx"> // Force refresh of plugin update information
</span><del>- delete_site_transient('update_plugins');
- wp_cache_delete( 'plugins', 'plugins' );
</del><ins>+ wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
+
</ins><span class="cx"> do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin', 'bulk' => true ), $plugins );
</span><span class="cx">
</span><span class="cx"> return $results;
</span><span class="lines">@@ -755,38 +776,47 @@
</span><span class="cx"> return $actions;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function install($package) {
</del><ins>+ function install( $package, $args = array() ) {
</ins><span class="cx">
</span><ins>+ $defaults = array(
+ 'clear_update_cache' => true,
+ );
+ $parsed_args = wp_parse_args( $defaults, $args );
+
</ins><span class="cx"> $this->init();
</span><span class="cx"> $this->install_strings();
</span><span class="cx">
</span><span class="cx"> add_filter('upgrader_source_selection', array($this, 'check_package') );
</span><span class="cx"> add_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'), 10, 3);
</span><span class="cx">
</span><del>- $options = array(
</del><ins>+ $this->run( array(
</ins><span class="cx"> 'package' => $package,
</span><span class="cx"> 'destination' => get_theme_root(),
</span><span class="cx"> 'clear_destination' => false, //Do not overwrite files.
</span><span class="cx"> 'clear_working' => true
</span><del>- );
</del><ins>+ ) );
</ins><span class="cx">
</span><del>- $this->run($options);
-
</del><span class="cx"> remove_filter('upgrader_source_selection', array($this, 'check_package') );
</span><span class="cx"> remove_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'));
</span><span class="cx">
</span><span class="cx"> if ( ! $this->result || is_wp_error($this->result) )
</span><span class="cx"> return $this->result;
</span><span class="cx">
</span><del>- // Force refresh of theme update information
- wp_clean_themes_cache();
</del><ins>+ // Refresh the Theme Update information
+ wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
+
</ins><span class="cx"> do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'theme' ), $package );
</span><span class="cx">
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function upgrade($theme) {
</del><ins>+ function upgrade( $theme, $args = array() ) {
</ins><span class="cx">
</span><ins>+ $defaults = array(
+ 'clear_update_cache' => true,
+ );
+ $parsed_args = wp_parse_args( $defaults, $args );
+
</ins><span class="cx"> $this->init();
</span><span class="cx"> $this->upgrade_strings();
</span><span class="cx">
</span><span class="lines">@@ -806,7 +836,7 @@
</span><span class="cx"> add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2);
</span><span class="cx"> add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4);
</span><span class="cx">
</span><del>- $options = array(
</del><ins>+ $this->run( array(
</ins><span class="cx"> 'package' => $r['package'],
</span><span class="cx"> 'destination' => get_theme_root( $theme ),
</span><span class="cx"> 'clear_destination' => true,
</span><span class="lines">@@ -814,10 +844,8 @@
</span><span class="cx"> 'hook_extra' => array(
</span><span class="cx"> 'theme' => $theme
</span><span class="cx"> ),
</span><del>- );
</del><ins>+ ) );
</ins><span class="cx">
</span><del>- $this->run($options);
-
</del><span class="cx"> remove_filter('upgrader_pre_install', array($this, 'current_before'));
</span><span class="cx"> remove_filter('upgrader_post_install', array($this, 'current_after'));
</span><span class="cx"> remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme'));
</span><span class="lines">@@ -825,15 +853,20 @@
</span><span class="cx"> if ( ! $this->result || is_wp_error($this->result) )
</span><span class="cx"> return $this->result;
</span><span class="cx">
</span><del>- // Force refresh of theme update information
- wp_clean_themes_cache();
</del><ins>+ wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
+
</ins><span class="cx"> do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme' ), $theme );
</span><span class="cx">
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function bulk_upgrade($themes) {
</del><ins>+ function bulk_upgrade( $themes, $args = array() ) {
</ins><span class="cx">
</span><ins>+ $defaults = array(
+ 'clear_update_cache' => true,
+ );
+ $parsed_args = wp_parse_args( $defaults, $args );
+
</ins><span class="cx"> $this->init();
</span><span class="cx"> $this->bulk = true;
</span><span class="cx"> $this->upgrade_strings();
</span><span class="lines">@@ -886,7 +919,7 @@
</span><span class="cx"> // Get the URL to the zip file
</span><span class="cx"> $r = $current->response[ $theme ];
</span><span class="cx">
</span><del>- $options = array(
</del><ins>+ $result = $this->run( array(
</ins><span class="cx"> 'package' => $r['package'],
</span><span class="cx"> 'destination' => get_theme_root( $theme ),
</span><span class="cx"> 'clear_destination' => true,
</span><span class="lines">@@ -894,10 +927,8 @@
</span><span class="cx"> 'hook_extra' => array(
</span><span class="cx"> 'theme' => $theme
</span><span class="cx"> ),
</span><del>- );
</del><ins>+ ) );
</ins><span class="cx">
</span><del>- $result = $this->run($options);
-
</del><span class="cx"> $results[$theme] = $this->result;
</span><span class="cx">
</span><span class="cx"> // Prevent credentials auth screen from displaying multiple times
</span><span class="lines">@@ -916,8 +947,9 @@
</span><span class="cx"> remove_filter('upgrader_post_install', array($this, 'current_after'));
</span><span class="cx"> remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme'));
</span><span class="cx">
</span><del>- // Force refresh of theme update information
- wp_clean_themes_cache();
</del><ins>+ // Refresh the Theme Update information
+ wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
+
</ins><span class="cx"> do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme', 'bulk' => true ), $themes );
</span><span class="cx">
</span><span class="cx"> return $results;
</span><span class="lines">@@ -1038,9 +1070,13 @@
</span><span class="cx"> $this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- function upgrade($current) {
</del><ins>+ function upgrade( $current, $args = array() ) {
</ins><span class="cx"> global $wp_filesystem, $wp_version;
</span><span class="cx">
</span><ins>+ $defaults = array(
+ );
+ $parsed_args = wp_parse_args( $defaults, $args );
+
</ins><span class="cx"> $this->init();
</span><span class="cx"> $this->upgrade_strings();
</span><span class="cx">
</span></span></pre></div>
<a id="trunksrcwpadminincludespluginphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/plugin.php (25271 => 25272)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/plugin.php 2013-09-06 01:20:17 UTC (rev 25271)
+++ trunk/src/wp-admin/includes/plugin.php 2013-09-06 01:32:09 UTC (rev 25272)
</span><span class="lines">@@ -1764,3 +1764,16 @@
</span><span class="cx"> echo '<input type="hidden" name="action" value="update" />';
</span><span class="cx"> wp_nonce_field("$option_group-options");
</span><span class="cx"> }
</span><ins>+
+/**
+ * Clears the Plugins cache used by get_plugins() and by default, the Plugin Update cache.
+ *
+ * @since 3.7.0
+ *
+ * @param bool $clear_update_cache Whether to clear the Plugin updates cache
+ */
+function wp_clean_plugins_cache( $clear_update_cache = true ) {
+ if ( $clear_update_cache )
+ delete_site_transient( 'update_plugins' );
+ wp_cache_delete( 'plugins', 'plugins' );
+}
</ins></span></pre></div>
<a id="trunksrcwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/theme.php (25271 => 25272)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/theme.php 2013-09-06 01:20:17 UTC (rev 25271)
+++ trunk/src/wp-includes/theme.php 2013-09-06 01:32:09 UTC (rev 25272)
</span><span class="lines">@@ -110,9 +110,11 @@
</span><span class="cx"> * Clears the cache held by get_theme_roots() and WP_Theme.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.5.0
</span><ins>+ * @param bool $clear_update_cache Whether to clear the Theme updates cache
</ins><span class="cx"> */
</span><del>-function wp_clean_themes_cache() {
- delete_site_transient('update_themes');
</del><ins>+function wp_clean_themes_cache( $clear_update_cache = true ) {
+ if ( $clear_update_cache )
+ delete_site_transient( 'update_themes' );
</ins><span class="cx"> search_theme_directories( true );
</span><span class="cx"> foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme )
</span><span class="cx"> $theme->cache_delete();
</span></span></pre>
</div>
</div>
</body>
</html>