Changeset 28567
- Timestamp:
- 05/23/2014 09:32:12 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/media.php
r28497 r28567 801 801 * @return string|WP_Error Populated HTML img tag on success 802 802 */ 803 function media_sideload_image($file, $post_id, $desc = null) { 804 if ( ! empty($file) ) { 805 // Download file to temp location 806 $tmp = download_url( $file ); 807 803 function media_sideload_image( $file, $post_id, $desc = null ) { 804 if ( ! empty( $file ) ) { 808 805 // Set variables for storage 809 806 // fix file filename for query strings 810 807 preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); 811 $file_array['name'] = basename( $matches[0]);812 $file_array['tmp_name'] = $tmp;813 814 // If error storing temporarily, unlink 815 if ( is_wp_error( $tmp ) ) {816 @unlink($file_array['tmp_name']);817 $file_array['tmp_name'] = '';808 $file_array['name'] = basename( $matches[0] ); 809 // Download file to temp location 810 $file_array['tmp_name'] = download_url( $file ); 811 812 // If error storing temporarily, return the error. 813 if ( is_wp_error( $file_array['tmp_name'] ) ) { 814 return $file_array['tmp_name']; 818 815 } 819 816 … … 821 818 $id = media_handle_sideload( $file_array, $post_id, $desc ); 822 819 // If error storing permanently, unlink 823 if ( is_wp_error( $id) ) {824 @unlink( $file_array['tmp_name']);820 if ( is_wp_error( $id ) ) { 821 @unlink( $file_array['tmp_name'] ); 825 822 return $id; 826 823 } … … 830 827 831 828 // Finally check to make sure the file has been saved, then return the html 832 if ( ! empty( $src) ) {833 $alt = isset( $desc) ? esc_attr($desc) : '';829 if ( ! empty( $src ) ) { 830 $alt = isset( $desc ) ? esc_attr( $desc ) : ''; 834 831 $html = "<img src='$src' alt='$alt' />"; 835 832 return $html;
Note: See TracChangeset
for help on using the changeset viewer.