[wp-trac] [WordPress Trac] #41726: `media_handle_upload()` may unexpectedly return 0 on error
WordPress Trac
noreply at wordpress.org
Fri Aug 25 12:52:58 UTC 2017
#41726: `media_handle_upload()` may unexpectedly return 0 on error
--------------------------+----------------------------------------
Reporter: flixos90 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version:
Severity: normal | Keywords: needs-patch good-first-bug
Focuses: |
--------------------------+----------------------------------------
The documentation of `media_handle_upload()` states that it will always
return the attachment ID on success, or a `WP_Error` object on failure,
which makes sense in my opinion.
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_upload()` 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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41726>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list