From 6295806d94b1cb741b7f5bcb8c0f7f3bfbb5851f Mon Sep 17 00:00:00 2001 From: latenighthackathon Date: Mon, 20 Apr 2026 22:27:56 -0500 Subject: [PATCH] fix[faustwp]: (#2311) clean up uploaded blockset zip when extraction fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When unzip_uploaded_file() returns a WP_Error in process_and_replace_blocks(), the uploaded zip was left behind in the target directory. On repeat failures this accumulates dead files on disk. Delete the target file before returning the error so the upload slot stays clean. Mirrors the existing cleanup_temp_directory() call on the success path. Split out from #2312 per @josephfusco review feedback — the hash_equals security hardening half stays on that PR so each can be reviewed and reverted independently. --- .changeset/blockset-cleanup-on-failed-extraction.md | 5 +++++ plugins/faustwp/includes/blocks/functions.php | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changeset/blockset-cleanup-on-failed-extraction.md diff --git a/.changeset/blockset-cleanup-on-failed-extraction.md b/.changeset/blockset-cleanup-on-failed-extraction.md new file mode 100644 index 000000000..f99669046 --- /dev/null +++ b/.changeset/blockset-cleanup-on-failed-extraction.md @@ -0,0 +1,5 @@ +--- +"@faustwp/wordpress-plugin": patch +--- + +fix[faustwp]: clean up uploaded blockset zip when extraction fails diff --git a/plugins/faustwp/includes/blocks/functions.php b/plugins/faustwp/includes/blocks/functions.php index 716e2ff71..8253f4053 100644 --- a/plugins/faustwp/includes/blocks/functions.php +++ b/plugins/faustwp/includes/blocks/functions.php @@ -53,6 +53,7 @@ function process_and_replace_blocks( $wp_filesystem, $file, $dirs ) { $unzip_result = unzip_uploaded_file( $target_file, $dirs['target'] ); if ( is_wp_error( $unzip_result ) ) { + $wp_filesystem->delete( $target_file ); return $unzip_result; }