// Re-generate attachment metadata since it was previously generated for a different theme.
$metadata =
wp_generate_attachment_metadata( $attachment_post->ID,
$attached_file );
wp_update_attachment_metadata( $attachment_id,
$metadata );
update_post_meta( $attachment_id, '_starter_content_theme',
$this->
get_stylesheet() );
} } // Insert the attachment auto-draft because it doesn't yet exist or the attached file is gone.
if ( !
$attachment_id ) { // Copy file to temp location so that original file won't get deleted from theme after sideloading.
$temp_file_name =
wp_tempnam( wp_basename( $file_path ) );
if ( $temp_file_name &&
copy( $file_path,
$temp_file_name ) ) { $file_array['tmp_name'
] =
$temp_file_name;
} if ( empty( $file_array['tmp_name'
] ) ) { continue;
} $attachment_post_data =
array_merge( wp_array_slice_assoc( $attachment, array
( 'post_title', 'post_content', 'post_excerpt'
) ),
array
( 'post_status' => 'auto-draft', // So attachment will be garbage collected in a week if changeset is never published.