Upgrader: Make clearing the Plugin and Theme update caches optional during install and upgrade proceedures. See #22704

Built from https://develop.svn.wordpress.org/trunk@25272


git-svn-id: http://core.svn.wordpress.org/trunk@25238 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2013-09-06 01:33:09 +00:00
parent 4b40e7a646
commit 443aa35cfc
3 changed files with 130 additions and 79 deletions

View File

@ -166,10 +166,14 @@ class WP_Upgrader {
function install_package( $args = array() ) { function install_package( $args = array() ) {
global $wp_filesystem, $wp_theme_directories; global $wp_filesystem, $wp_theme_directories;
$defaults = array( 'source' => '', 'destination' => '', //Please always pass these $defaults = array(
'clear_destination' => false, 'clear_working' => false, 'source' => '', // Please always pass this
'destination' => '', // and this
'clear_destination' => false,
'clear_working' => false,
'abort_if_destination_exists' => true, 'abort_if_destination_exists' => true,
'hook_extra' => array()); 'hook_extra' => array()
);
$args = wp_parse_args($args, $defaults); $args = wp_parse_args($args, $defaults);
extract($args); extract($args);
@ -277,7 +281,8 @@ class WP_Upgrader {
function run($options) { function run($options) {
$defaults = array( 'package' => '', //Please always pass this. $defaults = array(
'package' => '', // Please always pass this.
'destination' => '', // And this 'destination' => '', // And this
'clear_destination' => false, 'clear_destination' => false,
'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please 'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please
@ -331,6 +336,7 @@ class WP_Upgrader {
'clear_working' => $clear_working, 'clear_working' => $clear_working,
'hook_extra' => $hook_extra 'hook_extra' => $hook_extra
) ); ) );
$this->skin->set_result($result); $this->skin->set_result($result);
if ( is_wp_error($result) ) { if ( is_wp_error($result) ) {
$this->skin->error($result); $this->skin->error($result);
@ -398,7 +404,12 @@ class Plugin_Upgrader extends WP_Upgrader {
$this->strings['process_success'] = __('Plugin installed successfully.'); $this->strings['process_success'] = __('Plugin installed successfully.');
} }
function install($package) { function install( $package, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $defaults, $args );
$this->init(); $this->init();
$this->install_strings(); $this->install_strings();
@ -419,14 +430,19 @@ class Plugin_Upgrader extends WP_Upgrader {
return $this->result; return $this->result;
// Force refresh of plugin update information // Force refresh of plugin update information
delete_site_transient('update_plugins'); wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
wp_cache_delete( 'plugins', 'plugins' );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'plugin' ), $package ); do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'plugin' ), $package );
return true; return true;
} }
function upgrade($plugin) { function upgrade( $plugin, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $defaults, $args );
$this->init(); $this->init();
$this->upgrade_strings(); $this->upgrade_strings();
@ -454,7 +470,7 @@ class Plugin_Upgrader extends WP_Upgrader {
'clear_working' => true, 'clear_working' => true,
'hook_extra' => array( 'hook_extra' => array(
'plugin' => $plugin 'plugin' => $plugin
) ),
) ); ) );
// Cleanup our hooks, in case something else does a upgrade on this connection. // Cleanup our hooks, in case something else does a upgrade on this connection.
@ -465,14 +481,19 @@ class Plugin_Upgrader extends WP_Upgrader {
return $this->result; return $this->result;
// Force refresh of plugin update information // Force refresh of plugin update information
delete_site_transient('update_plugins'); wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
wp_cache_delete( 'plugins', 'plugins' );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin' ), $plugin ); do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin' ), $plugin );
return true; return true;
} }
function bulk_upgrade($plugins) { function bulk_upgrade( $plugins, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $defaults, $args );
$this->init(); $this->init();
$this->bulk = true; $this->bulk = true;
@ -553,8 +574,8 @@ class Plugin_Upgrader extends WP_Upgrader {
remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin')); remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'));
// Force refresh of plugin update information // Force refresh of plugin update information
delete_site_transient('update_plugins'); wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
wp_cache_delete( 'plugins', 'plugins' );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin', 'bulk' => true ), $plugins ); do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin', 'bulk' => true ), $plugins );
return $results; return $results;
@ -755,7 +776,12 @@ class Theme_Upgrader extends WP_Upgrader {
return $actions; return $actions;
} }
function install($package) { function install( $package, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $defaults, $args );
$this->init(); $this->init();
$this->install_strings(); $this->install_strings();
@ -763,14 +789,12 @@ class Theme_Upgrader extends WP_Upgrader {
add_filter('upgrader_source_selection', array($this, 'check_package') ); add_filter('upgrader_source_selection', array($this, 'check_package') );
add_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'), 10, 3); add_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'), 10, 3);
$options = array( $this->run( array(
'package' => $package, 'package' => $package,
'destination' => get_theme_root(), 'destination' => get_theme_root(),
'clear_destination' => false, //Do not overwrite files. 'clear_destination' => false, //Do not overwrite files.
'clear_working' => true 'clear_working' => true
); ) );
$this->run($options);
remove_filter('upgrader_source_selection', array($this, 'check_package') ); remove_filter('upgrader_source_selection', array($this, 'check_package') );
remove_filter('upgrader_post_install', array($this, 'check_parent_theme_filter')); remove_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'));
@ -778,14 +802,20 @@ class Theme_Upgrader extends WP_Upgrader {
if ( ! $this->result || is_wp_error($this->result) ) if ( ! $this->result || is_wp_error($this->result) )
return $this->result; return $this->result;
// Force refresh of theme update information // Refresh the Theme Update information
wp_clean_themes_cache(); wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'theme' ), $package ); do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'theme' ), $package );
return true; return true;
} }
function upgrade($theme) { function upgrade( $theme, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $defaults, $args );
$this->init(); $this->init();
$this->upgrade_strings(); $this->upgrade_strings();
@ -806,7 +836,7 @@ class Theme_Upgrader extends WP_Upgrader {
add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2); add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2);
add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4); add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4);
$options = array( $this->run( array(
'package' => $r['package'], 'package' => $r['package'],
'destination' => get_theme_root( $theme ), 'destination' => get_theme_root( $theme ),
'clear_destination' => true, 'clear_destination' => true,
@ -814,9 +844,7 @@ class Theme_Upgrader extends WP_Upgrader {
'hook_extra' => array( 'hook_extra' => array(
'theme' => $theme 'theme' => $theme
), ),
); ) );
$this->run($options);
remove_filter('upgrader_pre_install', array($this, 'current_before')); remove_filter('upgrader_pre_install', array($this, 'current_before'));
remove_filter('upgrader_post_install', array($this, 'current_after')); remove_filter('upgrader_post_install', array($this, 'current_after'));
@ -825,14 +853,19 @@ class Theme_Upgrader extends WP_Upgrader {
if ( ! $this->result || is_wp_error($this->result) ) if ( ! $this->result || is_wp_error($this->result) )
return $this->result; return $this->result;
// Force refresh of theme update information wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
wp_clean_themes_cache();
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme' ), $theme ); do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme' ), $theme );
return true; return true;
} }
function bulk_upgrade($themes) { function bulk_upgrade( $themes, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $defaults, $args );
$this->init(); $this->init();
$this->bulk = true; $this->bulk = true;
@ -886,7 +919,7 @@ class Theme_Upgrader extends WP_Upgrader {
// Get the URL to the zip file // Get the URL to the zip file
$r = $current->response[ $theme ]; $r = $current->response[ $theme ];
$options = array( $result = $this->run( array(
'package' => $r['package'], 'package' => $r['package'],
'destination' => get_theme_root( $theme ), 'destination' => get_theme_root( $theme ),
'clear_destination' => true, 'clear_destination' => true,
@ -894,9 +927,7 @@ class Theme_Upgrader extends WP_Upgrader {
'hook_extra' => array( 'hook_extra' => array(
'theme' => $theme 'theme' => $theme
), ),
); ) );
$result = $this->run($options);
$results[$theme] = $this->result; $results[$theme] = $this->result;
@ -916,8 +947,9 @@ class Theme_Upgrader extends WP_Upgrader {
remove_filter('upgrader_post_install', array($this, 'current_after')); remove_filter('upgrader_post_install', array($this, 'current_after'));
remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme')); remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme'));
// Force refresh of theme update information // Refresh the Theme Update information
wp_clean_themes_cache(); wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme', 'bulk' => true ), $themes ); do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme', 'bulk' => true ), $themes );
return $results; return $results;
@ -1038,9 +1070,13 @@ class Core_Upgrader extends WP_Upgrader {
$this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' ); $this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' );
} }
function upgrade($current) { function upgrade( $current, $args = array() ) {
global $wp_filesystem, $wp_version; global $wp_filesystem, $wp_version;
$defaults = array(
);
$parsed_args = wp_parse_args( $defaults, $args );
$this->init(); $this->init();
$this->upgrade_strings(); $this->upgrade_strings();

View File

@ -1764,3 +1764,16 @@ function settings_fields($option_group) {
echo '<input type="hidden" name="action" value="update" />'; echo '<input type="hidden" name="action" value="update" />';
wp_nonce_field("$option_group-options"); wp_nonce_field("$option_group-options");
} }
/**
* 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' );
}

View File

@ -110,8 +110,10 @@ function wp_get_theme( $stylesheet = null, $theme_root = null ) {
* Clears the cache held by get_theme_roots() and WP_Theme. * Clears the cache held by get_theme_roots() and WP_Theme.
* *
* @since 3.5.0 * @since 3.5.0
* @param bool $clear_update_cache Whether to clear the Theme updates cache
*/ */
function wp_clean_themes_cache() { function wp_clean_themes_cache( $clear_update_cache = true ) {
if ( $clear_update_cache )
delete_site_transient( 'update_themes' ); delete_site_transient( 'update_themes' );
search_theme_directories( true ); search_theme_directories( true );
foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme )