#55158 closed defect (bug) (fixed)
Attachment removed from grid view if the delete request is failed
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.0 | Priority: | normal |
Severity: | normal | Version: | 6.0 |
Component: | Media | Keywords: | has-patch needs-testing |
Focuses: | ui, javascript | Cc: |
Description
While working with media attachments got a bug. When try to delete a media attachment from modal by pressing Delete permanently
button, if the ajax request response is failed the media attachment is removed from the list.
Steps to reproduce:
- Add
pre_delete_attachment
filter in your theme'sfunctions.php
to prevent the delete attachment operation.
add_filter( 'pre_delete_attachment', function ( $delete, $attachment ) { return false; }, 10, 2 );
- Go to Media (grid mode)
https://example.com/wp-admin/upload.php?mode=grid
- Click on any attachment. (The modal will open)
- Click on
Delete permanently
button- This will remove the attachment from grid list.
- If you check the Ajax request the response is 0
- After done, reload the page. (The image is still there)
Expected Result:
If the media cannot be deleted or the response is failed, the Attachment should be there. It should not be removed.
Actual Result:
If the media cannot be deleted or the response is failed, the Attachment is getting removed from the list.
Change History (12)
This ticket was mentioned in PR #2315 on WordPress/wordpress-develop by kapilpaul.
3 years ago
#1
- Keywords has-patch added
#3
@
3 years ago
- Keywords needs-testing added
Hi there!
Thanks for the ticket and patch.
I tested the patch and it working fine without any error.
Let's add needs-testing
so the testing team can help to test this issue in the next meeting.
#5
@
3 years ago
Env
- Web Server: Apache
- WordPress: 6.0-alpha-52448-src
- Browser: Chrome
- OS: Linux
- Theme: Twenty Twenty-One
- Plugins: None activated
Reproc Report
Steps to reproduce
- Add this filter to
functions.php
:
<?php add_filter( 'pre_delete_attachment', '__return_false', 10, 2 );
- Navigate to
Media > Library
. - Enable Grid mode.
- Click on a media item to open the modal.
- Click
Delete permanently
.- The media item will no longer show in the grid. ✅
- If you check the Ajax request the response is
0
. ✅
- Reload the page. The media item is still in the list. ✅
Results
- Issue reproduced. ✅
Test Report
Steps to test
- Add this filter to
functions.php
:
<?php add_filter( 'pre_delete_attachment', '__return_false', 10, 2 );
- Apply PR 2315.
- Run
npm run build:dev
. - Navigate to
Media > Library
. - Enable Grid mode.
- Click on a media item to open the modal.
- Click
Delete permanently
. Nothing will happen. ✅ - Close the modal. The media item is still in the list. ✅
- Reload the page. The media item is still in the list. ✅
Results
- PR 2315 successfully resolves the issue. ✅
Comments
While the PR prevents the media item from being removed from the list, the end result is that Delete permanently
, to a user, appears to do nothing. I think the PR would benefit from informing the user that the media item could not be deleted.
For example, this will create an alert when the media item cannot be deleted:
// src/wp-includes/media.php:4495
'couldNotDeleteMediaItem' => __( 'The media item could not be deleted.' ),
// src/js/media/views/attachment/details.js:157 this.model.destroy( { wait: true, error: function() { alert( l10n.couldNotDeleteMediaItem ); } } );
#6
@
3 years ago
@costdev thanks for testing this. I am also agree with your comment. We need to inform/display some message to end user. I will update the PR with the suggested.
SergeyBiryukov commented on PR #2315:
3 years ago
#10
Thanks for the PR! I think we can use an existing string here: Error in deleting the attachment
, which we already use in a few other places. Looks good to me otherwise.
Trac ticket: https://core.trac.wordpress.org/ticket/55158