diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 225a7d4c69..d4db2b082d 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -150,8 +150,9 @@ class WP_Upgrader { * @since 5.9.0 */ protected function schedule_temp_backup_cleanup() { - wp_schedule_event( time(), 'weekly', 'delete_temp_updater_backups' ); - add_action( 'delete_temp_updater_backups', array( $this, 'delete_all_temp_backups' ) ); + if ( false === wp_next_scheduled( 'wp_delete_temp_updater_backups' ) ) { + wp_schedule_event( time(), 'weekly', 'wp_delete_temp_updater_backups' ); + } } /** @@ -1107,51 +1108,6 @@ class WP_Upgrader { true ); } - - /** - * Deletes all contents of the temp-backup directory. - * - * @since 5.9.0 - * - * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. - */ - public function delete_all_temp_backups() { - /* - * Check if there's a lock, or if currently performing an Ajax request, - * in which case there's a chance we're doing an update. - * 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, 'delete_temp_updater_backups' ); - return; - } - - add_action( - 'shutdown', - /* - * This action runs on shutdown to make sure there's no plugin updates currently running. - * Using a closure in this case is OK since the action can be removed by removing the parent hook. - */ - function() { - global $wp_filesystem; - - if ( ! $wp_filesystem ) { - include_once ABSPATH . '/wp-admin/includes/file.php'; - WP_Filesystem(); - } - - $dirlist = $wp_filesystem->dirlist( $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' ); - - foreach ( array_keys( $dirlist ) as $dir ) { - if ( '.' === $dir || '..' === $dir ) { - continue; - } - - $wp_filesystem->delete( $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' . $dir, true ); - } - } - ); - } } /** Plugin_Upgrader class */ diff --git a/wp-includes/update.php b/wp-includes/update.php index 42ae3ecf3a..e17c38d0ce 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -956,6 +956,51 @@ function wp_clean_update_cache() { delete_site_transient( 'update_core' ); } +/** + * Deletes all contents of the temp-backup directory. + * + * @since 5.9.0 + * + * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. + */ +function wp_delete_all_temp_backups() { + /* + * Check if there's a lock, or if currently performing an Ajax request, + * in which case there's a chance we're doing an update. + * 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; + } + + add_action( + 'shutdown', + /* + * This action runs on shutdown to make sure there's no plugin updates currently running. + * Using a closure in this case is OK since the action can be removed by removing the parent hook. + */ + function() { + global $wp_filesystem; + + if ( ! $wp_filesystem ) { + include_once ABSPATH . '/wp-admin/includes/file.php'; + WP_Filesystem(); + } + + $dirlist = $wp_filesystem->dirlist( $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' ); + + foreach ( array_keys( $dirlist ) as $dir ) { + if ( '.' === $dir || '..' === $dir ) { + continue; + } + + $wp_filesystem->delete( $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' . $dir, true ); + } + } + ); +} + if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) { return; } @@ -980,3 +1025,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' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 40af19f916..701c43afed 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52191'; +$wp_version = '5.9-alpha-52192'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.