#56170 closed defect (bug) (fixed)
Bulk delete media attachments doesn't pass integer values to wp_delete_attachment
Reported by: | eherman24 | Owned by: | joedolson |
---|---|---|---|
Milestone: | 6.2 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | has-patch commit |
Focuses: | administration | Cc: |
Description
When selecting multiple images in the media table on /wp-admin/upload.php and using the bulk delete dropdown to delete images passes a string value to wp_delete_attachment()
. This could cause some issues for methods hooked into into deleted_post
.
The documentation for the deleted_post
hook indicates the first parameter is an integer.
https://developer.wordpress.org/reference/hooks/deleted_post/
<?php do_action( 'deleted_post', int $postid, WP_Post $post );
To confirm that the $postid
value is a string I ran the following test code to hook into deleted_post
and update an option in the database based on the value of $postid
.
<?php add_action( 'deleted_post', function( $post_id ) { update_option( 'test_post_integer_value', is_int( $post_id ) ); }, PHP_INT_MAX, 2 );
Deleting a single image, using the 'Delete Permanently' button on either the media list table or the media grid will update the test_post_integer_value
option value to 1 (true).
Switching over to the media list table view, and using the checkboxes to select 1 or more images, and then using the bulk delete dropdown to delete the images results in a false value. The option value is empty in the database.
So it's worth noting this only happens using the bulk delete actions dropdown on the media list table. Even when selecting a single image.
Attachments (3)
Change History (15)
#1
@
3 years ago
I added an updated patch, the first one included an unnecessary typecast of $post_id_del
to current_user_can()
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
2 years ago
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
2 years ago
#8
@
2 years ago
- Keywords 2nd-opinion removed
- Status changed from reviewing to accepted
The provided patch fixes the immediate issue, but doesn't cover the same issue with wp_trash_post
and wp_untrash_post
earlier in the same function, which also expect int
arguments.
Alternate version of patch ensures that $post_ids
is an array of integers from the beginning of the function, simplifying the code by making the (array) and (int) casting unnecessary.
This ticket was mentioned in PR #3957 on WordPress/wordpress-develop by @joedolson.
2 years ago
#9
Ensure that post IDs passed to wp_trash_post
, wp_untrash_post
, and wp_delete_attachment
are always of type int
.
Trac ticket: https://core.trac.wordpress.org/ticket/56170
@joedolson commented on PR #3957:
2 years ago
#12
Fixed in r55183
Updated diff.