Media: Dismiss button not functional on upload errors.
Some checks failed
Cleanup Pull Requests / Clean up pull requests (push) Waiting to run
Coding Standards / PHP coding standards (push) Waiting to run
Coding Standards / JavaScript coding standards (push) Waiting to run
Coding Standards / Slack Notifications (push) Blocked by required conditions
Coding Standards / Failed workflow tasks (push) Blocked by required conditions
End-to-end Tests / Test with SCRIPT_DEBUG disabled (push) Waiting to run
End-to-end Tests / Test with SCRIPT_DEBUG enabled (push) Waiting to run
End-to-end Tests / Slack Notifications (push) Blocked by required conditions
End-to-end Tests / Failed workflow tasks (push) Blocked by required conditions
JavaScript Tests / QUnit Tests (push) Waiting to run
JavaScript Tests / Slack Notifications (push) Blocked by required conditions
JavaScript Tests / Failed workflow tasks (push) Blocked by required conditions
Performance Tests / Determine Matrix (push) Waiting to run
Performance Tests / ${{ matrix.multisite && 'Multisite' || 'Single Site' }} ${{ matrix.memcached && 'Memcached' || 'Default' }} (push) Blocked by required conditions
Performance Tests / Compare (push) Blocked by required conditions
Performance Tests / Slack Notifications (push) Blocked by required conditions
Performance Tests / Failed workflow tasks (push) Blocked by required conditions
PHP Compatibility / Check PHP compatibility (push) Waiting to run
PHP Compatibility / Slack Notifications (push) Blocked by required conditions
PHP Compatibility / Failed workflow tasks (push) Blocked by required conditions
PHPUnit Tests / PHP 7.2 (push) Waiting to run
PHPUnit Tests / PHP 7.3 (push) Waiting to run
PHPUnit Tests / PHP 7.4 (push) Waiting to run
PHPUnit Tests / PHP 8.0 (push) Waiting to run
PHPUnit Tests / PHP 8.1 (push) Waiting to run
PHPUnit Tests / PHP 8.2 (push) Waiting to run
PHPUnit Tests / PHP 8.3 (push) Waiting to run
PHPUnit Tests / PHP 8.4 (push) Waiting to run
PHPUnit Tests / html-api-html5lib-tests (push) Waiting to run
PHPUnit Tests / Slack Notifications (push) Blocked by required conditions
PHPUnit Tests / Failed workflow tasks (push) Blocked by required conditions
Test Build Processes / Core running from build (push) Waiting to run
Test Build Processes / Core running from src (push) Waiting to run
Test Build Processes / Gutenberg running from build (push) Waiting to run
Test Build Processes / Gutenberg running from src (push) Waiting to run
Test Build Processes / Slack Notifications (push) Blocked by required conditions
Test Build Processes / Failed workflow tasks (push) Blocked by required conditions
Upgrade Develop Version Tests / Build (push) Waiting to run
Upgrade Develop Version Tests / Upgrade from 4.9 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.5 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.6 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.7 (push) Blocked by required conditions
Upgrade Develop Version Tests / Slack Notifications (push) Blocked by required conditions
Upgrade Develop Version Tests / Failed workflow tasks (push) Blocked by required conditions
Installation Tests / Build Test Matrix (push) Has been cancelled
Installation Tests / WP ${{ inputs.wp-version || 'nightly' }} / PHP ${{ matrix.php }} / ${{ 'mariadb' == matrix.db-type && 'MariaDB' || 'MySQL' }} ${{ matrix.db-version }}${{ matrix.multisite && ' multisite' || '' }} (push) Has been cancelled
Installation Tests / Slack Notifications (push) Has been cancelled
Installation Tests / Failed workflow tasks (push) Has been cancelled

Change the `onclick` attribute to a separate inlined script in the error message and improve the event attachment behavior.

Props vivekawsm, mijotj, adamsilverstein, parthvataliya, adhun, sarathar, peterwilsoncc, sayedulsayem, chaion07, sppramodh, indirabiswas27, aishwarryapande, dhrumilk, manojmaharrshi, ugyensupport, imranhasanraaz, pkbhatt, shailu25, joedolson.
Fixes #60074.

git-svn-id: https://develop.svn.wordpress.org/trunk@59986 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Dolson 2025-03-16 16:09:13 +00:00
parent ed2f2ecd3f
commit 6f8d4e2b7d
3 changed files with 41 additions and 2 deletions

View File

@ -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 <strong>%s</strong><br />%s',
sprintf(
'<button type="button" class="dismiss button-link" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">%s</button>',
'<button type="button" id="%s" class="dismiss button-link">%s</button>',
esc_attr( $button_unique_id ),
__( 'Dismiss' )
),
sprintf(
@ -132,6 +134,7 @@ if ( is_wp_error( $id ) ) {
'paragraph_wrap' => false,
)
);
echo "<script>jQuery( 'button#{$button_unique_id}' ).on( 'click', function() {jQuery(this).parents('div.media-item').slideUp(200, function(){jQuery(this).remove();})});</script>\n";
exit;
}

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="800" height="450" viewBox="0 0 800 450"> <rect fill="#0F1C3F" width="800" height="450"/> <text fill="#7FDBFF" font-family="sans-serif" font-size="90" dy="31.499999999999996" font-weight="bold" x="50%" y="50%" text-anchor="middle">800×450</text> </svg>

After

Width:  |  Height:  |  Size: 299 B

View File

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