wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_delete_all_temp_backups › WordPress Function

Since5.9.0
Deprecatedn/a
wp_delete_all_temp_backups ( No parameters )
Defined at:
Codex:

Deletes all contents of the temp-backup directory.



Source

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 );
			}
		}
	);
}