Make WordPress Core

Ticket #19629: media-sideload.diff

File media-sideload.diff, 1.3 KB (added by whyisjake, 8 years ago)

Media sideload, return the post ID

  • wp-admin/includes/media.php

    diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php
    index 194e827..e0aa97d 100644
    a b function wp_media_upload_handler() { 
    846846 * @param string $file    The URL of the image to download.
    847847 * @param int    $post_id The post ID the media is to be associated with.
    848848 * @param string $desc    Optional. Description of the image.
    849  * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'.
     849 * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'.
    850850 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise.
    851851 */
    852852function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) {
    function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) 
    872872                // Do the validation and storage stuff.
    873873                $id = media_handle_sideload( $file_array, $post_id, $desc );
    874874
     875                // If we want a simple out to get to the image ID, make it available here.
     876                if ( $return === 'id' ) {
     877                        return $id;
     878                }
     879
    875880                // If error storing permanently, unlink.
    876881                if ( is_wp_error( $id ) ) {
    877882                        @unlink( $file_array['tmp_name'] );