When a file such as an image is uploaded, an optimized version is created with $saved = $editor->save($editor->generate_filename('name'));
. This successfully writes the file to disk and the intermediate sizes are created too from the source/original image.
I'd like to add the optimized version to the array of sizes. I've tried the following but no additional size is added to the metadata array.
$metadata['sizes']['full'] = [];
$metadata['sizes']['full']['file'] = $saved['file'];
$metadata['sizes']['full']['width'] = $saved['width'];
$metadata['sizes']['full']['height'] = $saved['height'];
$metadata['sizes']['full']['mime-type'] = $saved['mime-type'];
$metadata['sizes']['full']['filesize'] = $saved['filesize'];
I've attempted $metadata['sizes'] = array('full' => $saved,);
but again the 'full' size isn't added/appended to the list existing array.
How can I go about adding/pushing/merging it?
add_filter('wp_generate_attachment_metadata'