[wp-trac] [WordPress Trac] #18185: media_handle_sideload clears $title if $desc is not set
WordPress Trac
wp-trac at lists.automattic.com
Wed Jul 20 16:45:51 UTC 2011
#18185: media_handle_sideload clears $title if $desc is not set
--------------------------+-----------------------------
Reporter: baldgoat | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.2.1
Severity: normal | Keywords:
--------------------------+-----------------------------
media_handle_sideload() -- found in wp-admin>includes>media.php -- is
setting $title to an empty string if isset($desc) returns false.
{{{
function media_handle_sideload($file_array, $post_id, $desc = null,
$post_data = array()) {
$overrides = array('test_form'=>false);
$file = wp_handle_sideload($file_array, $overrides);
if ( isset($file['error']) )
return new WP_Error( 'upload_error', $file['error'] );
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$title = preg_replace('/\.[^.]+$/', '', basename($file));
$content = '';
// use image exif/iptc data for title and caption defaults if
possible
if ( $image_meta = @wp_read_image_metadata($file) ) {
if ( trim( $image_meta['title'] ) && ! is_numeric(
sanitize_title( $image_meta['title'] ) ) )
$title = $image_meta['title'];
if ( trim( $image_meta['caption'] ) )
$content = $image_meta['caption'];
}
$title = isset($desc) ? $desc : '';
// Construct the attachment array
$attachment = array_merge( array(
'post_mime_type' => $type,
'guid' => $url,
'post_parent' => $post_id,
'post_title' => $title,
'post_content' => $content,
), $post_data );
// Save the attachment metadata
$id = wp_insert_attachment($attachment, $file, $post_id);
if ( !is_wp_error($id) )
wp_update_attachment_metadata( $id,
wp_generate_attachment_metadata( $id, $file ) );
return $id;
}
}}}
Please note this line:
{{{
$title = isset($desc) ? $desc : '';
}}}
$desc is NULL by default. So if a value is not passed in the function
call, $title will be set to an empty string.
It appears that it should be changed to this
{{{
$title = isset($desc) ? $desc : $title;
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/18185>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list