[wp-trac] [WordPress Trac] #44303: `media_handle_sideload()` may unexpectedly return 0 on error
WordPress Trac
noreply at wordpress.org
Tue Jun 5 08:06:00 UTC 2018
#44303: `media_handle_sideload()` may unexpectedly return 0 on error
--------------------------+-----------------------------
Reporter: jirihon | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44303>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list