diff --git a/src/wp-admin/async-upload.php b/src/wp-admin/async-upload.php
index 683fd83248..2ac2f20e76 100644
--- a/src/wp-admin/async-upload.php
+++ b/src/wp-admin/async-upload.php
@@ -112,10 +112,12 @@ if ( isset( $_REQUEST['post_id'] ) ) {
$id = media_handle_upload( 'async-upload', $post_id );
if ( is_wp_error( $id ) ) {
- $message = sprintf(
+ $button_unique_id = uniqid( 'dismiss-' );
+ $message = sprintf(
'%s %s
%s',
sprintf(
- '',
+ '',
+ esc_attr( $button_unique_id ),
__( 'Dismiss' )
),
sprintf(
@@ -132,6 +134,7 @@ if ( is_wp_error( $id ) ) {
'paragraph_wrap' => false,
)
);
+ echo "\n";
exit;
}
diff --git a/tests/e2e/assets/sample.svg b/tests/e2e/assets/sample.svg
new file mode 100644
index 0000000000..faccd78697
--- /dev/null
+++ b/tests/e2e/assets/sample.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/tests/e2e/specs/media-upload.test.js b/tests/e2e/specs/media-upload.test.js
new file mode 100644
index 0000000000..885dee92c9
--- /dev/null
+++ b/tests/e2e/specs/media-upload.test.js
@@ -0,0 +1,35 @@
+/**
+ * WordPress dependencies
+ */
+import { test, expect } from '@wordpress/e2e-test-utils-playwright';
+
+/**
+ * External dependencies
+ */
+import path from 'path';
+
+test( 'Test dismissing failed upload works correctly', async ({ page, admin, requestUtils }) => {
+ // Log in before visiting admin page.
+ await requestUtils.login();
+ await admin.visitAdminPage( '/media-new.php' );
+
+ // It takes a moment for the multi-file uploader to become available.
+ await page.waitForLoadState('load');
+
+ const testImagePath = path.join(__dirname, '../assets/sample.svg');
+
+ // Upload a file that will fail.
+ const input = page.locator( '#plupload-upload-ui input[type="file"]' );
+ await input.setInputFiles( testImagePath );
+
+ // Ensure the error message is visible.
+ await expect(
+ page.getByText('“sample.svg” has failed to upload.')
+ ).toBeVisible();
+
+ // Ensure the error message is dismissed.
+ await page.getByRole('button', { name: 'Dismiss' }).click();
+ await expect(
+ page.getByText('“sample.svg” has failed to upload.')
+ ).not.toBeVisible();
+} );