Repository navigation
Conversation
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>
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue: #1159
While an Image Storage rollback ran, new uploads were still offloaded to Optimole. During a rollback
offload_mediais off, butis_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 whileoffload_mediais 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 onlygenerate_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()throughupload_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/mfolder is restored later in that rollback, WordPress gives the restored file a-1suffix (the #1136 area).Tests
tests/test-media.php: withoffload_mediaoff and a rollback in progress,instance()registers neither hook (but still serves offloaded URLs), and a new upload keeps a localfilein its metadata and on disk. The test fails ondevelopment.QA
On a connected site with offloaded images, start Transfer back from Optimole in
WP Admin → Optimole → Settings → Image Storage.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.With Image Storage on and no transfer running, upload another image.
Expect: it is offloaded as before.
Verification (head
1714a7e0)tests/test-media.phprun alonedevelopmentsourcephpcs,phpstan(build-only include errors excluded locally; CI builds assets first)Not proven
🤖 Generated with Claude Code