Use of the “wp_update_attachment_metadata” filter as “upload is complete” hook

As previously mentioned in Updates to Image Processing in WordPress 5.3 and Introducing handling of big images in WordPress 5.3, there have been changes in image post-processing after upload.

In WordPress 5.3, the image metadata is saved after each intermediate size is created to allow the processing of images to happen over multiple requests. This means the wp_update_attachment_metadata filter is run repeatedly while the image sub-sizes are being created. This fulfills the intended use of the filter, to let plugins “filter” the metadata before saving it to the database. It runs on all metadata updates, like when editing an attachment post, in wp_ajax_crop_image(), or to update the ID3 data for audio files.

However, some plugins are using the wp_update_attachment_metadata filter as an “upload is complete” hook (#48451). The changes in 5.3 are great for plugins that benefit from processing smaller amounts of information/images at a time, but may trigger more overhead/unneeded processing for plugins that bulk process images using that filter. A better hook to use for these cases is wp_generate_attachment_metadata.

An alternative solution may be to add context (by adding another parameter) to the wp_update_attachment_metadata filter.

The most likely plugins to be affected are those that use wp_update_attachment_metadata to do additional post-processing of uploaded files. After a plugin repo search, some examples of plugins that do this are Smush Image Compression and Optimization, WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage, EWWW Image Optimizer, ShortPixel Image Optimizer, Compress JPEG & PNG images, Imagify – WebP & Image Compression and Optimization, a3 Lazy Load.

It would be ideal if the authors of potentially affected plugins could test and update them, if necessary, to continue working well in WordPress 5.3 or share any difficulties encountered on #48451.