Ticket #19629: media_sideload_image.diff
File media_sideload_image.diff, 1.1 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/media.php
586 586 * @param string $file The URL of the image to download 587 587 * @param int $post_id The post ID the media is to be associated with 588 588 * @param string $desc Optional. Description of the image 589 * @return string|WP_Error Populated HTML img tag on success 589 * @param string $html Optional. Return html markup if true, attach id if false 590 * @return string|int|WP_Error Populated HTML img tag or attachment id on success 590 591 */ 591 function media_sideload_image($file, $post_id, $desc = null ) {592 function media_sideload_image($file, $post_id, $desc = null, $html = true) { 592 593 if ( ! empty($file) ) { 593 594 // Download file to temp location 594 595 $tmp = download_url( $file ); … … 620 621 if ( ! empty($src) ) { 621 622 $alt = isset($desc) ? esc_attr($desc) : ''; 622 623 $html = "<img src='$src' alt='$alt' />"; 623 return $html; 624 if ( $html ) { 625 return $html; 626 } else { 627 return $id; 628 } 624 629 } 625 630 } 626 631