Ensure that images added using Press This get the correct source url set. Fixes #15841 props duck_.
git-svn-id: https://develop.svn.wordpress.org/trunk@17120 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
cd4f625268
commit
64e7465e1c
|
@ -270,7 +270,7 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data =
|
||||||
$content = $image_meta['caption'];
|
$content = $image_meta['caption'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = @$desc;
|
$title = isset($desc) ? $desc : '';
|
||||||
|
|
||||||
// Construct the attachment array
|
// Construct the attachment array
|
||||||
$attachment = array_merge( array(
|
$attachment = array_merge( array(
|
||||||
|
@ -547,19 +547,19 @@ function media_upload_image() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@internal Missing Short Description}}
|
* Download an image from the specified URL and attach it to a post.
|
||||||
*
|
*
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*
|
*
|
||||||
* @param unknown_type $file
|
* @param string $file The URL of the image to download
|
||||||
* @param unknown_type $post_id
|
* @param int $post_id The post ID the media is to be associated with
|
||||||
* @param unknown_type $desc
|
* @param string $desc Optional. Description of the image
|
||||||
* @return unknown
|
* @return string|WP_Error Populated HTML img tag on success
|
||||||
*/
|
*/
|
||||||
function media_sideload_image($file, $post_id, $desc = null) {
|
function media_sideload_image($file, $post_id, $desc = null) {
|
||||||
if (!empty($file) ) {
|
if ( ! empty($file) ) {
|
||||||
// Download file to temp location
|
// Download file to temp location
|
||||||
$tmp = download_url($file);
|
$tmp = download_url( $file );
|
||||||
|
|
||||||
// Set variables for storage
|
// Set variables for storage
|
||||||
// fix file filename for query strings
|
// fix file filename for query strings
|
||||||
|
@ -574,19 +574,19 @@ function media_sideload_image($file, $post_id, $desc = null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the validation and storage stuff
|
// do the validation and storage stuff
|
||||||
$id = media_handle_sideload( $file_array, $post_id, @$desc );
|
$id = media_handle_sideload( $file_array, $post_id, $desc );
|
||||||
$src = get_attachment_link( $id );
|
|
||||||
|
|
||||||
// If error storing permanently, unlink
|
// If error storing permanently, unlink
|
||||||
if ( is_wp_error($id) ) {
|
if ( is_wp_error($id) ) {
|
||||||
@unlink($file_array['tmp_name']);
|
@unlink($file_array['tmp_name']);
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$src = wp_get_attachment_url( $id );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally check to make sure the file has been saved, then return the html
|
// Finally check to make sure the file has been saved, then return the html
|
||||||
if ( !empty($src) ) {
|
if ( ! empty($src) ) {
|
||||||
$alt = @$desc;
|
$alt = isset($desc) ? esc_attr($desc) : '';
|
||||||
$html = "<img src='$src' alt='$alt' />";
|
$html = "<img src='$src' alt='$alt' />";
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue