Make WordPress Core

Ticket #33879: media-sideload-image.diff

File media-sideload-image.diff, 1.0 KB (added by arkimedia, 10 years ago)

Media Sideload Image function Git diff

  • wp-admin/includes/media.php

    diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php
    index fc8ce0f..b9e2a32 100755
    a b function wp_media_upload_handler() { 
    834834 * @param string $file    The URL of the image to download.
    835835 * @param int    $post_id The post ID the media is to be associated with.
    836836 * @param string $desc    Optional. Description of the image.
    837  * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'.
     837 * @param string $return  Optional. Accepts 'html' (image tag html) 'id' (image ID) or 'src' (URL). Default 'html'.
    838838 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise.
    839839 */
    840840function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) {
    function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) 
    862862                        return $id;
    863863                }
    864864
     865                if( $return === 'id' ){
     866                        return $id;
     867                }
     868
    865869                $src = wp_get_attachment_url( $id );
    866870        }
    867871