Changeset 40597 – WordPress Trac (original) (raw)
Timestamp:
05/09/2017 11:25:56 PM (9 years ago)
mikeschroder
Message:
Media: Optionally return attachment id from media_sideload_image().
Introduces option to $return parameter to return the attachment id created after a successful image sideload.
Props slbmeh, kawauso, alexkingorg, SergeyBiryukov, georgestephanis, DrewAPicture, nacin, trepmal, mattheu, kraftbj, whyisjake, dotancohen, MrGregWaugh, danielbachhuber.
Fixes #19629.
File:
Legend:
Unmodified
Added
Removed
| r40400 | r40597 | |
|---|---|---|
| 853 | 853 | * @since 2.6.0 |
| 854 | 854 | * @since 4.2.0 Introduced the `$return` parameter. |
| 855 | * @since 4.8.0 Introduced the 'id' option within the `$return` parameter. | |
| 855 | 856 | * |
| 856 | 857 | * @param string $file The URL of the image to download. |
| 857 | 858 | * @param int $post_id The post ID the media is to be associated with. |
| 858 | 859 | * @param string $desc Optional. Description of the image. |
| 859 | * @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'. | |
| 860 | * @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'. | |
| 860 | 861 | * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise. |
| 861 | 862 | */ |
| … | … | |
| 886 | 887 | if ( is_wp_error( $id ) ) { |
| 887 | 888 | @unlink( $file_array['tmp_name'] ); |
| 889 | return $id; | |
| 890 | // If attachment id was requested, return it early. | |
| 891 | } elseif ( $return === 'id' ) { | |
| 888 | 892 | return $id; |
| 889 | 893 | } |
Note: See TracChangeset for help on using the changeset viewer.