Make WordPress Core

Ticket #15841: 15841.2.diff

File 15841.2.diff, 1.9 KB (added by duck_, 16 years ago)
  • wp-admin/includes/media.php

     
    270270                        $content = $image_meta['caption'];
    271271        }
    272272
    273         $title = @$desc;
     273        $title = isset($desc) ? $desc : '';
    274274
    275275        // Construct the attachment array
    276276        $attachment = array_merge( array(
     
    547547}
    548548
    549549/**
    550  * {@internal Missing Short Description}}
     550 * Download an image from the specified URL and attach it to a post.
    551551 *
    552552 * @since 2.6.0
    553553 *
    554  * @param unknown_type $file
    555  * @param unknown_type $post_id
    556  * @param unknown_type $desc
    557  * @return unknown
     554 * @param string $file The URL of the image to download
     555 * @param int $post_id The post ID the media is to be associated with
     556 * @param string $desc Optional. Description of the image
     557 * @return string|WP_Error Populated HTML img tag on success
    558558 */
    559559function media_sideload_image($file, $post_id, $desc = null) {
    560         if (!empty($file) ) {
     560        if ( ! empty($file) ) {
    561561                // Download file to temp location
    562                 $tmp = download_url($file);
     562                $tmp = download_url( $file );
    563563
    564564                // Set variables for storage
    565565                // fix file filename for query strings
     
    574574                }
    575575
    576576                // do the validation and storage stuff
    577                 $id = media_handle_sideload( $file_array, $post_id, @$desc );
    578                 $src = get_attachment_link( $id );
    579 
     577                $id = media_handle_sideload( $file_array, $post_id, $desc );
    580578                // If error storing permanently, unlink
    581579                if ( is_wp_error($id) ) {
    582580                        @unlink($file_array['tmp_name']);
    583581                        return $id;
    584582                }
     583
     584                $src = wp_get_attachment_url( $id );
    585585        }
    586586
    587587        // Finally check to make sure the file has been saved, then return the html
    588         if ( !empty($src) ) {
    589                 $alt = @$desc;
     588        if ( ! empty($src) ) {
     589                $alt = isset($desc) ? esc_attr($desc) : '';
    590590                $html = "<img src='$src' alt='$alt' />";
    591591                return $html;
    592592        }