WordPress.org

Make WordPress Core

Ticket #19629: media_sideload_image.diff

File media_sideload_image.diff, 1.1 KB (added by slbmeh, 9 years ago)
  • wp-admin/includes/media.php

     
    586586 * @param string $file The URL of the image to download
    587587 * @param int $post_id The post ID the media is to be associated with
    588588 * @param string $desc Optional. Description of the image
    589  * @return string|WP_Error Populated HTML img tag on success
     589 * @param string $html Optional. Return html markup if true, attach id if false
     590 * @return string|int|WP_Error Populated HTML img tag or attachment id on success
    590591 */
    591 function media_sideload_image($file, $post_id, $desc = null) {
     592function media_sideload_image($file, $post_id, $desc = null, $html = true) {
    592593        if ( ! empty($file) ) {
    593594                // Download file to temp location
    594595                $tmp = download_url( $file );
     
    620621        if ( ! empty($src) ) {
    621622                $alt = isset($desc) ? esc_attr($desc) : '';
    622623                $html = "<img src='$src' alt='$alt' />";
    623                 return $html;
     624                if ( $html ) {
     625                        return $html;
     626                } else {
     627                        return $id;
     628                }
    624629        }
    625630}
    626631