Make WordPress Core

Ticket #15432: media_handle_sideload.patch

File media_handle_sideload.patch, 1.2 KB (added by joostdevalk, 14 years ago)

Patch

  • wp-admin/includes/media.php

     
    283283
    284284        // Save the attachment metadata
    285285        $id = wp_insert_attachment($attachment, $file, $post_id);
    286         if ( !is_wp_error($id) ) {
     286        if ( !is_wp_error($id) )
    287287                wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    288                 return $url;
    289         }
     288
    290289        return $id;
    291290}
    292291
     
    518517                $file_array['tmp_name'] = $tmp;
    519518
    520519                // If error storing temporarily, unlink
    521                 if ( is_wp_error($tmp) ) {
     520                if ( is_wp_error( $tmp ) ) {
    522521                        @unlink($file_array['tmp_name']);
    523522                        $file_array['tmp_name'] = '';
    524523                }
    525524
    526525                // do the validation and storage stuff
    527                 $id = media_handle_sideload($file_array, $post_id, @$desc);
    528                 $src = $id;
     526                $id = media_handle_sideload( $file_array, $post_id, @$desc );
    529527
    530528                // If error storing permanently, unlink
    531529                if ( is_wp_error($id) ) {
    532530                        @unlink($file_array['tmp_name']);
    533531                        return $id;
    534532                }
     533
     534                $src = get_attachment_link( $id );
    535535        }
    536536
    537537        // Finally check to make sure the file has been saved, then return the html