﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
18185,media_handle_sideload clears $title if $desc is not set,baldgoat,duck_,"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;
}}}


",defect (bug),closed,normal,3.3,Media,3.2.1,normal,fixed,has-patch commit,
