Opened 21 months ago
Closed 13 months ago
#44303 closed defect (bug) (fixed)
`media_handle_sideload()` may unexpectedly return 0 on error
Reported by: | jirihon | Owned by: | joemcgill |
---|---|---|---|
Milestone: | 5.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | has-patch commit |
Focuses: | Cc: | ||
PR Number: |
Description
This is closely related to #41726. The documentation of media_handle_sideload()
(same as for media_handle_upload()
) states that it will always return the attachment ID on success, or a WP_Error
object on failure. However, it currently may return 0 as well if something fails with the attachment post insertion. That is because wp_insert_attachment()
and wp_insert_post()
do not return WP_Error
objects by default, and media_handle_sideload()
for some reason does not change this like it should.
This requires a simple fix: call wp_insert_attachment()
with the fourth parameter set to true as it was recently fixed for the media_handle_upload()
in #41726.
Attachments (1)
Change History (6)
#2
@
20 months ago
- Keywords commit added
- Owner set to joemcgill
- Status changed from new to accepted
Thanks for the writeup, @jirihon and for the patch, @subrataemfluence. It looks good to me.
One quick note on ticket process, the version
property on a ticket is meant to refer to the version of WordPress where a bug was introduced and/or the earliest version where you can reproduce this bug. I don't really see a need to go back through WP history to identify that moment in this instance.
Cheers!
Proposed patch