ThumbnailRegenerationObserver & AttachmentUpdateObserver conflicting?
-
On a wordpress 6.9.4 installation, with “full cloud migration” enabled, when editing an image (e.g. applying a crop via the media gallery) the image fails to offload.
After some debugging it appears both the
ThumbnailRegenerationObserverandAttachmentUpdateObserverclasses are being triggered, resulting in the first call offloading the files and the second fall failing due to the files missing on disk.This causes the previously offloaded file to become “local” with an error along the lines of:
Failed to upload size 'medium' to cloud storage. Please review your Cloud provider credentials or connection settings. For more details, enable debug.log and check the logs.And a PHP error along the lines of:
[02-May-2026 15:28:34 UTC] Advanced Media Offloader: Error uploading file to S3: Unable to open "/workspace/wp-content/uploads/a74c6b052aef9b72c958734e525d9d7a-e1777735712599-289x300.jpeg" using mode "r": fopen(/workspace/wp-content/uploads/a74c6b052aef9b72c958734e525d9d7a-e1777735712599-289x300.jpeg): Failed to open stream: No such file or directoryDisabling the
ThumbnailRegenerationObserverwhich is gated to only be run with images allows the images to be edited successfully, an example hook for this is as below:// Disable uploads triggered by ThumbnailRegenerationObserver if
add_filter(
'advmo_should_offload_attachment',
function($should_offload, $attachment_id) {
$found_image_save = $found_thumbnail_observer = false;
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10) as $element) {
if (
array_key_exists( 'class', $element ) &&
$element['class'] == 'Advanced_Media_Offloader\Observers\ThumbnailRegenerationObserver' &&
array_key_exists( 'function', $element ) &&
$element['function'] == 'run'
) {
$found_thumbnail_observer = true;
}
if ( array_key_exists( 'function', $element ) && $element['function'] == 'wp_save_image' ) {
$found_image_save = true;
}
if( $found_thumbnail_observer && $found_image_save ) {
return false;
}
}
return true;
},
10,
2
);Image edited was previously working, but I’ve not been able to pin down exactly where this stopped working.
The most basic reproduction steps:
- Enable the plugin with “Full Cloud Migration”
- Upload an image
- Edit the image
- Observe saving the edited image fails
You must be logged in to reply to this topic.