[wp-trac] [WordPress Trac] #56170: Bulk delete media attachments doesn't pass integer values to wp_delete_attachment
WordPress Trac
noreply at wordpress.org
Thu Jul 7 23:20:07 UTC 2022
#56170: Bulk delete media attachments doesn't pass integer values to
wp_delete_attachment
----------------------------+-----------------------------------
Reporter: eherman24 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: trunk
Severity: normal | Keywords: has-patch 2nd-opinion
Focuses: administration |
----------------------------+-----------------------------------
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
<?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
<?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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56170>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list