Skip to content

fix: keep new uploads local while an Image Storage rollback runs - #1174

Open
selul wants to merge 1 commit into
developmentfrom
bugfix/1159
Open

selul wants to merge 1 commit into
developmentfrom
bugfix/1159

Conversation

@selul

@selul selul commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Related issue: #1159

While an Image Storage rollback ran, new uploads were still offloaded to Optimole. During a rollback offload_media is off, but is_offload_enabled() stays true so that already offloaded images keep being served from Optimole, and that also kept the upload hooks on. New uploads now stay in the media library while a rollback runs.

What changed

  • Optml_Media_Offload::instance() — two hooks are registered only while offload_media is on, not during a rollback:
    • wp_generate_attachment_metadata → generate_image_meta(), which offloads a new upload;
    • wp_insert_attachment_data → insert() / insert_legacy(), the filename deduplication offloaded uploads need because their local files are deleted. It renames the attached file, and only generate_image_meta() maps that name back, so the two must be gated together.

Note

Everything that serves offloaded images (URL, srcset, attachment and editor filters) stays registered during the rollback, as before. Bulk offload, single-image moves and the Abilities API call generate_image_meta() through upload_and_update_existing_images(), not the hook, so they are unaffected.

One narrow side effect to know: an upload made during a rollback keeps its local file. If a not-yet-restored offloaded image with the same file name in the same uploads/Y/m folder is restored later in that rollback, WordPress gives the restored file a -1 suffix (the #1136 area).

Tests

  • tests/test-media.php: with offload_media off and a rollback in progress, instance() registers neither hook (but still serves offloaded URLs), and a new upload keeps a local file in its metadata and on disk. The test fails on development.

QA

  1. On a connected site with offloaded images, start Transfer back from Optimole in WP Admin → Optimole → Settings → Image Storage.

  2. While it runs, upload a new image in Media → Add New.

    Expect: the new image's URL points to wp-content/uploads/…, and the file exists on the server.

  3. With Image Storage on and no transfer running, upload another image.

    Expect: it is offloaded as before.

Verification (head 1714a7e0)

Check Result
PHPUnit, full suite, PHP 8.4 (WP 7.1.3) PASS: 365 tests (baseline 364 + 1 new)
tests/test-media.php run alone PASS: 24 tests
New test on the development source FAILS
phpcs, phpstan (build-only include errors excluded locally; CI builds assets first) PASS

Not proven

  • On a live site: the local test site is not connected to Optimole, so uploads cannot be offloaded there.

🤖 Generated with Claude Code

During a rollback, offload_media is off but is_offload_enabled() stays true
so that already offloaded images keep being served from Optimole. That also
kept the upload hooks on, so a new upload was offloaded while everything
else was being moved back. generate_image_meta() and the filename
deduplication in insert() are now registered only while offload_media is
on; they belong together, because insert() renames the attached file for
offloaded uploads only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pirate-bot

Copy link
Copy Markdown
Collaborator

Plugin build for 1714a7e is ready 🛎️!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants