function wp_generate_attachment_metadata( $attachment_id,
$file ) { $attachment =
get_post( $attachment_id );
$metadata = array
();
$support = false;
$mime_type =
get_post_mime_type( $attachment );
if ( preg_match( '!^image/!',
$mime_type ) &&
file_is_displayable_image( $file ) ) { // Make thumbnails and other intermediate sizes.
$metadata =
wp_create_image_subsizes( $file,
$attachment_id );
} elseif ( wp_attachment_is( 'video',
$attachment ) ) { $metadata =
wp_read_video_metadata( $file );
$support =
current_theme_supports( 'post-thumbnails', 'attachment:video'
) ||
post_type_supports( 'attachment:video', 'thumbnail'
);
} elseif ( wp_attachment_is( 'audio',
$attachment ) ) { $metadata =
wp_read_audio_metadata( $file );
$support =
current_theme_supports( 'post-thumbnails', 'attachment:audio'
) ||
post_type_supports( 'attachment:audio', 'thumbnail'
);
} /*
* wp_read_video_metadata() and wp_read_audio_metadata() return `false`
* if the attachment does not exist in the local filesystem,
* so make sure to convert the value to an array.
*/