WordPress.org

Make WordPress Core

Ticket #15432: media_handle_sideload.2.patch

File media_handle_sideload.2.patch, 1.8 KB (added by joostdevalk, 4 years ago)

Same patch now with documentation fixed too

  • wp-admin/includes/media.php

     
    241241/** 
    242242 * {@internal Missing Short Description}} 
    243243 * 
     244 * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()} 
     245 * 
    244246 * @since unknown 
    245247 * 
    246  * @param unknown_type $file_array 
    247  * @param unknown_type $post_id 
    248  * @param unknown_type $desc 
    249  * @param unknown_type $post_data 
    250  * @return unknown 
     248 * @param array $file_array Array similar to a {@link $_FILES} upload array 
     249 * @param int $post_id The post ID the media is associated with 
     250 * @param string $desc Description of the sideloaded file 
     251 * @param array $post_data allows you to overwrite some of the attachment 
     252 * @return int the ID of the attachment 
    251253 */ 
    252254function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { 
    253255        $overrides = array('test_form'=>false); 
     
    283285 
    284286        // Save the attachment metadata 
    285287        $id = wp_insert_attachment($attachment, $file, $post_id); 
    286         if ( !is_wp_error($id) ) { 
     288        if ( !is_wp_error($id) ) 
    287289                wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 
    288                 return $url; 
    289         } 
     290 
    290291        return $id; 
    291292} 
    292293 
     
    518519                $file_array['tmp_name'] = $tmp; 
    519520 
    520521                // If error storing temporarily, unlink 
    521                 if ( is_wp_error($tmp) ) { 
     522                if ( is_wp_error( $tmp ) ) { 
    522523                        @unlink($file_array['tmp_name']); 
    523524                        $file_array['tmp_name'] = ''; 
    524525                } 
    525526 
    526527                // do the validation and storage stuff 
    527                 $id = media_handle_sideload($file_array, $post_id, @$desc); 
    528                 $src = $id; 
     528                $id = media_handle_sideload( $file_array, $post_id, @$desc ); 
     529                $src = get_attachment_link( $id ); 
    529530 
    530531                // If error storing permanently, unlink 
    531532                if ( is_wp_error($id) ) {