[wp-trac] [WordPress Trac] #55158: Attachment removed from grid view if the delete request is failed

WordPress Trac noreply at wordpress.org
Sun Feb 13 18:48:39 UTC 2022


#55158: Attachment removed from grid view if the delete request is failed
-------------------------------------+-----------------------------
 Reporter:  kapilpaul                |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  6.0
Component:  Media                    |     Version:  trunk
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:  ui, javascript
-------------------------------------+-----------------------------

Comment (by costdev):

 === 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
 1. Add this filter to `functions.php`:

 {{{#!php
 <?php
 add_filter( 'pre_delete_attachment', '__return_false', 10, 2 );
 }}}
 2. Navigate to `Media > Library`.
 3. Enable Grid mode.
 4. Click on a media item to open the modal.
 5. Click `Delete permanently`.
  - The media item will no longer show in the grid. ✅
  - If you check the Ajax request the response is `0`. ✅
 6. Reload the page. The media item is still in the list. ✅

 === Results
 - Issue reproduced. ✅

 ----

 == Test Report

 === Steps to test
 1. Add this filter to `functions.php`:

 {{{#!php
 <?php
 add_filter( 'pre_delete_attachment', '__return_false', 10, 2 );
 }}}
 2. Apply [https://github.com/WordPress/wordpress-develop/pull/2315 PR
 2315].
 3. Run `npm run build:dev`.
 4. Navigate to `Media > Library`.
 5. Enable Grid mode.
 6. Click on a media item to open the modal.
 7. Click `Delete permanently`. Nothing will happen. ✅
 8. Close the modal. The media item is still in the list. ✅
 9. Reload the page. The media item is still in the list. ✅

 === Results
 - [https://github.com/WordPress/wordpress-develop/pull/2315 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 image cannot be deleted:

 {{{#!php
 // src/wp-includes/media.php:4495

 'couldNotDeleteMediaItem'     => __( 'The media item could not be
 deleted.' ),
 }}}

 {{{#!js
 // src/js/media/views/attachment/details.js:157

 this.model.destroy( {
         wait: true,
         error: function() {
                 alert( l10n.couldNotDeleteMediaItem );
         }
 } );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55158#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list