函数文档

wp_delete_all_temp_backups()

💡 云策文档标注

概述

wp_delete_all_temp_backups() 函数用于调度删除临时备份目录中的所有内容。它通过检查更新锁和 Ajax 请求状态,确保在安全时机执行清理操作。

关键要点

  • 函数检查 core_updater.lock、auto_updater.lock 选项或 wp_doing_ajax() 状态,以避免在更新或 Ajax 请求期间删除备份。
  • 如果存在锁或 Ajax 请求,函数会重新调度事件(一小时后)并提前返回。
  • 在安全条件下,函数通过 add_action() 在 shutdown 钩子上挂接 _wp_delete_all_temp_backups 来执行实际删除。
  • 相关函数包括 wp_doing_ajax()、wp_schedule_single_event()、add_action() 和 get_option()。
  • 此函数自 WordPress 6.3.0 版本引入。

📄 原文内容

Schedules the removal of all contents in the temporary backup directory.

Source

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

Changelog

Version Description
6.3.0 Introduced.