_wp_delete_all_temp_backups

函数
_wp_delete_all_temp_backups ( No parameters )
Access
Private
返回值
  • (void|WP_Error) Void on success, or a WP_Error object on failure.
定义位置
相关方法
wp_delete_all_temp_backups_wp_delete_tax_menu_itemwp_delete_termwp_mediaelement_fallbackwp_rel_callback
引入
6.3.0
弃用
-

删除临时备份目录中的所有内容。

function _wp_delete_all_temp_backups() {
	global $wp_filesystem;

	if ( ! function_exists( 'WP_Filesystem' ) ) {
		require_once ABSPATH . '/wp-admin/includes/file.php';
	}

	ob_start();
	$credentials = request_filesystem_credentials( '' );
	ob_end_clean();

	if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
		return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
	}

	if ( ! $wp_filesystem->wp_content_dir() ) {
		return new WP_Error(
			'fs_no_content_dir',
			/* translators: %s: Directory name. */
			sprintf( __( 'Unable to locate WordPress content directory (%s).' ), '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 );
	}
}

常见问题

FAQs
查看更多 >