Make WordPress Core


Ignore:
Timestamp:
09/17/2009 08:36:59 PM (17 years ago)
Author:
ryan
Message:

Press This fixes. Props noel. fixes #10784

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r11911 r11944  
    250250function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
    251251        $overrides = array('test_form'=>false);
     252       
    252253        $file = wp_handle_sideload($file_array, $overrides);
    253 
    254254        if ( isset($file['error']) )
    255255                return new WP_Error( 'upload_error', $file['error'] );
     
    280280        ), $post_data );
    281281
    282         // Save the data
     282        // Save the attachment metadata
    283283        $id = wp_insert_attachment($attachment, $file, $post_id);
    284284        if ( !is_wp_error($id) ) {
     
    521521function media_sideload_image($file, $post_id, $desc = null) {
    522522        if (!empty($file) ) {
    523                 $file_array['name'] = basename($file);
     523                // Download file to temp location
    524524                $tmp = download_url($file);
     525               
     526                // Set variables for storage
     527                // fix file filename for query strings
     528                preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
     529                $file_array['name'] = basename($matches[0]);
    525530                $file_array['tmp_name'] = $tmp;
    526                 $desc = @$desc;
    527 
     531
     532                // If error storing temporarily, unlink
    528533                if ( is_wp_error($tmp) ) {
    529534                        @unlink($file_array['tmp_name']);
    530535                        $file_array['tmp_name'] = '';
    531536                }
    532 
    533                 $id = media_handle_sideload($file_array, $post_id, $desc);
     537               
     538                // do the validation and storage stuff
     539                $id = media_handle_sideload($file_array, $post_id, @$desc);
    534540                $src = $id;
    535 
     541               
     542                // If error storing permanently, unlink
    536543                if ( is_wp_error($id) ) {
    537544                        @unlink($file_array['tmp_name']);
     
    539546                }
    540547        }
    541 
     548       
     549        // Finally check to make sure the file has been saved, then return the html
    542550        if ( !empty($src) ) {
    543551                $alt = @$desc;
Note: See TracChangeset for help on using the changeset viewer.