// 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.
) );
$attachment_id =
media_handle_sideload( $file_array, 0, null,
$attachment_post_data );
if ( is_wp_error( $attachment_id ) ) { continue;
} update_post_meta( $attachment_id, '_starter_content_theme',
$this->
get_stylesheet() );
update_post_meta( $attachment_id, '_customize_draft_post_name',
$attachment['post_name'
] );
}