mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-03 04:04:35 +00:00
Upgrade/Install: Create a temporary backup of plugins and themes before updating.
This aims to make the update process more reliable and ensures that if a plugin or theme update fails, the previous version can be safely restored. * When updating a plugin or theme, the old version is moved to a temporary backup directory: * `wp-content/upgrade-temp-backup/plugins/[plugin-slug]` for plugins * `wp-content/upgrade-temp-backup/themes/[theme-slug]` for themes. * If the update fails, then the backup kept in the temporary backup directory is restored to its original location. * If the update succeeds, the temporary backup is deleted. To further help troubleshoot plugin and theme updates, two new checks were added to the Site Health screen: * A check to make sure that the `upgrade-temp-backup` directory is writable. * A check that there is enough disk space available to safely perform updates. To avoid confusion: The temporary backup directory will NOT be used to “roll back” a plugin to a previous version after a completed update. This directory will simply contain a transient backup of the previous version of a plugin or theme being updated, and as soon as the update process finishes, the directory will be empty. Follow-up to [55204], [55220]. Props afragen, costdev, pbiron, azaozz, hellofromTonya, aristath, peterwilsoncc, TJNowell, bronsonquick, Clorith, dd32, poena, TimothyBlynJacobs, audrasjb, mikeschroder, a2hosting, KZeni, galbaras, richards1052, Boniu91, mai21, francina, TobiasBg, desrosj, noisysocks, johnbillion, dlh, chaion07, davidbaumwald, jrf, thisisyeasin, ignatggeorgiev, SergeyBiryukov. Fixes #51857. git-svn-id: https://develop.svn.wordpress.org/trunk@55720 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1077,6 +1077,62 @@ function wp_clean_update_cache() {
|
||||
delete_site_transient( 'update_core' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the removal of all contents in the temporary backup directory.
|
||||
*
|
||||
* @since 6.3.0
|
||||
*/
|
||||
function wp_delete_all_temp_backups() {
|
||||
/*
|
||||
* Check if there is a lock, or if currently performing an Ajax request,
|
||||
* in which case there is a chance an update is running.
|
||||
* Reschedule for an hour from now and exit early.
|
||||
*/
|
||||
if ( get_option( 'core_updater.lock' ) || get_option( 'auto_updater.lock' ) || wp_doing_ajax() ) {
|
||||
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_delete_temp_updater_backups' );
|
||||
return;
|
||||
}
|
||||
|
||||
// This action runs on shutdown to make sure there are no plugin updates currently running.
|
||||
add_action( 'shutdown', '_wp_delete_all_temp_backups' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all contents in the temporary backup directory.
|
||||
*
|
||||
* @since 6.3.0
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
|
||||
*
|
||||
* @return void|WP_Error Void on success, or a WP_Error object on failure.
|
||||
*/
|
||||
function _wp_delete_all_temp_backups() {
|
||||
global $wp_filesystem;
|
||||
|
||||
if ( ! $wp_filesystem ) {
|
||||
require_once ABSPATH . '/wp-admin/includes/file.php';
|
||||
WP_Filesystem();
|
||||
}
|
||||
|
||||
if ( ! $wp_filesystem->wp_content_dir() ) {
|
||||
return new WP_Error( 'fs_no_content_dir', __( 'Unable to locate WordPress content directory (wp-content).' ) );
|
||||
}
|
||||
|
||||
$temp_backup_dir = $wp_filesystem->wp_content_dir() . 'upgrade-temp-backup/';
|
||||
$dirlist = $wp_filesystem->dirlist( $temp_backup_dir );
|
||||
$dirlist = $dirlist ? $dirlist : array();
|
||||
|
||||
foreach ( array_keys( $dirlist ) as $dir ) {
|
||||
if ( '.' === $dir || '..' === $dir ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$wp_filesystem->delete( $temp_backup_dir . $dir, true );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) {
|
||||
return;
|
||||
}
|
||||
@@ -1101,3 +1157,5 @@ add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 );
|
||||
add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
|
||||
|
||||
add_action( 'init', 'wp_schedule_update_checks' );
|
||||
|
||||
add_action( 'wp_delete_temp_updater_backups', 'wp_delete_all_temp_backups' );
|
||||
|
||||
Reference in New Issue
Block a user