Ticket #15432: media_handle_sideload.2.patch
File media_handle_sideload.2.patch, 1.8 KB (added by , 14 years ago) |
---|
-
wp-admin/includes/media.php
241 241 /** 242 242 * {@internal Missing Short Description}} 243 243 * 244 * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()} 245 * 244 246 * @since unknown 245 247 * 246 * @param unknown_type $file_array247 * @param unknown_type $post_id248 * @param unknown_type $desc249 * @param unknown_type $post_data250 * @return unknown248 * @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 251 253 */ 252 254 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { 253 255 $overrides = array('test_form'=>false); … … 283 285 284 286 // Save the attachment metadata 285 287 $id = wp_insert_attachment($attachment, $file, $post_id); 286 if ( !is_wp_error($id) ) {288 if ( !is_wp_error($id) ) 287 289 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 288 return $url; 289 } 290 290 291 return $id; 291 292 } 292 293 … … 518 519 $file_array['tmp_name'] = $tmp; 519 520 520 521 // If error storing temporarily, unlink 521 if ( is_wp_error( $tmp) ) {522 if ( is_wp_error( $tmp ) ) { 522 523 @unlink($file_array['tmp_name']); 523 524 $file_array['tmp_name'] = ''; 524 525 } 525 526 526 527 // 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 ); 529 530 530 531 // If error storing permanently, unlink 531 532 if ( is_wp_error($id) ) {