Title: [BUG] Object versioning: advmo_path saves wrong version after upload
Last modified: April 14, 2026

---

# [BUG] Object versioning: advmo_path saves wrong version after upload

 *  Resolved [Alessandro Carrera](https://wordpress.org/support/users/alessandrocarrera/)
 * (@alessandrocarrera)
 * [1 month, 4 weeks ago](https://wordpress.org/support/topic/bug-object-versioning-advmo_path-saves-wrong-version-after-upload/)
 * When object versioning is enabled, `updateAttachmentMetadata()` recalculates `
   get_attachment_subdir()` after the upload completes. Since `get_object_version()`
   generates the version from `date("dHis")`, even a 1-second delay between the 
   upload and the metadata save results in a different versioning string. Files 
   are uploaded to S3 at the correct path but `advmo_path` stores a different path,
   causing all images to appear broken. Environment:
    - Advanced Media Offloader: 4.4.1
    - WordPress: 6.9
    - PHP: 8.x
    - Cloud Provider: Amazon S3
    - Object Versioning: Enabled
    - Media organized by year/month: Yes
    - Other relevant installed plugins: EWWW Image Optimizer (WebP generation and
      PNG to JPG enabled), Regenerate Thumbnails
 * Steps to Reproduce
    1. Enable object versioning in ADVMO settings
    2. Upload a new image via Media Library (or click “Offload Now” on an existing 
       one)
    3. Wait for offload to complete
    4. Check `advmo_path` in `wp_postmeta` for the attachment
    5. Check S3 bucket for the actual file location
 * Expected Behavior
 * `advmo_path` should match the S3 key where files were uploaded. Actual Behavior
 * Files are uploaded to S3 at `wp-content/uploads/2026/04/14081741/image.jpg` but`
   advmo_path` is saved as `wp-content/uploads/2026/04/14081743/` (2 seconds later).
   The frontend then requests images from the wrong path, resulting in broken images(
   404). Debug Evidence
 * Added `error_log` calls to `S3_Provider::uploadFile()` to trace the actual `putObject`
   calls:
 *     ```wp-block-code
       ADVMO_DEBUG putObject BEFORE: Key=wp-content/uploads/2023/07/14081741/image.jpg | file_exists=YES
       ADVMO_DEBUG putObject SUCCESS: Key=wp-content/uploads/2023/07/14081741/image.jpg | StatusCode=200
       ```
   
 * All uploads go to versioning `14081741`. But the saved `advmo_path` post meta
   contains `14081743`.
 * On S3:
    - Folder `wp-content/uploads/2023/07/14081741/` EXISTS with all files
    - Folder `wp-content/uploads/2023/07/14081743/` DOES NOT EXIST
 * Root Cause
 * In `CloudAttachmentUploader.php`, the upload flow is:
    1. **Line 324** (`uploadToCloud`): `$subdir = $this->get_attachment_subdir($attachment_id)`–
       generates version `14081741` via `date("dHis")` and saves it to `advmo_object_version`
       meta
    2. All files are uploaded to S3 using this `$subdir`
    3. `uploadToCloud` returns `true`
    4. **Line 40** (`uploadAttachment`): calls `updateAttachmentMetadata($attachment_id)`
    5. **Line 534** (`updateAttachmentMetadata`): calls `$this->get_attachment_subdir(
       $attachment_id)` AGAIN
    6. `get_attachment_subdir` calls `get_object_version`, which somehow generates 
       a NEW version `14081743` instead of returning the saved one
 * The result: files on S3 at path with version X, `advmo_path` saved with version
   Y. Proposed Fix
 * `uploadToCloud()` should return the `$subdir` it used for the upload, and `updateAttachmentMetadata()`
   should receive it as a parameter instead of recalculating it.
 * **Before (current code):**
 *     ```wp-block-code
       // uploadAttachment()
       if ($this->uploadToCloud($attachment_id)) {
           $this->updateAttachmentMetadata($attachment_id);
           return true;
       }
   
       // uploadToCloud() returns bool
       private function uploadToCloud(int $attachment_id): bool
       {
           // ...
           return true;
       }
   
       // updateAttachmentMetadata() recalculates subdir
       private function updateAttachmentMetadata(int $attachment_id): void
       {
           update_post_meta($attachment_id, 'advmo_path', $this->get_attachment_subdir($attachment_id));
           // ...
       }
       ```
   
 * **After (proposed fix):**
 *     ```wp-block-code
       // uploadAttachment()
       $subdir = $this->uploadToCloud($attachment_id);
       if ($subdir !== false) {
           $this->updateAttachmentMetadata($attachment_id, $subdir);
           return true;
       }
   
       // uploadToCloud() returns the subdir used, or false on failure
       private function uploadToCloud(int $attachment_id): string|false
       {
           // ...
           return $subdir; // instead of return true
       }
   
       // updateAttachmentMetadata() uses the subdir from the upload
       private function updateAttachmentMetadata(int $attachment_id, string $subdir): void
       {
           update_post_meta($attachment_id, 'advmo_path', $subdir);
           // ...
       }
       ```
   
 * This ensures `advmo_path` always matches the actual S3 upload path. The fix has
   been tested and confirmed working.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Masoud Golchin](https://wordpress.org/support/users/masoudin/)
 * (@masoudin)
 * [1 month, 2 weeks ago](https://wordpress.org/support/topic/bug-object-versioning-advmo_path-saves-wrong-version-after-upload/#post-18889254)
 * Hi [@alessandrocarrera](https://wordpress.org/support/users/alessandrocarrera/)
   
   Thank you for reporting the compatibility bug with EWWW Image Optimizer.
 * I have created a ticket for this issue, and we will address it in the next release.
 *  Thread Starter [Alessandro Carrera](https://wordpress.org/support/users/alessandrocarrera/)
 * (@alessandrocarrera)
 * [1 month, 2 weeks ago](https://wordpress.org/support/topic/bug-object-versioning-advmo_path-saves-wrong-version-after-upload/#post-18889805)
 * HI [@masoudin](https://wordpress.org/support/users/masoudin/)
 * thank you so much!
 *  Plugin Author [Masoud Golchin](https://wordpress.org/support/users/masoudin/)
 * (@masoudin)
 * [5 days, 5 hours ago](https://wordpress.org/support/topic/bug-object-versioning-advmo_path-saves-wrong-version-after-upload/#post-18930982)
 * Hi [@alessandrocarrera](https://wordpress.org/support/users/alessandrocarrera/)
   
   We’ve identified the cause: the issue occurs when a persistent object cache (
   such as Redis or Memcached) is enabled. In that setup, the file location saved
   for an image couldoccasionally differ from where the file was actually uploaded—
   which is why the images appeared broken.
 * We’ve fixed this by making the plugin record the exact location used during the
   upload, so it no longer depends on the cache and the two can never fall out of
   sync.
 * The fix will be included in version 4.4.3, scheduled for release within the next
   few days. We recommend updating once it’s available.
 * Marking this ticket as resolved.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fbug-object-versioning-advmo_path-saves-wrong-version-after-upload%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/advanced-media-offloader/assets/icon.svg?rev=3213156)
 * [Advanced Media Offloader](https://wordpress.org/plugins/advanced-media-offloader/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-media-offloader/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-media-offloader/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-media-offloader/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-media-offloader/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-media-offloader/reviews/)

## Tags

 * [broken images](https://wordpress.org/support/topic-tag/broken-images/)
 * [s3](https://wordpress.org/support/topic-tag/s3/)

 * 3 replies
 * 2 participants
 * Last reply from: [Masoud Golchin](https://wordpress.org/support/users/masoudin/)
 * Last activity: [5 days, 5 hours ago](https://wordpress.org/support/topic/bug-object-versioning-advmo_path-saves-wrong-version-after-upload/#post-18930982)
 * Status: resolved