Skip to content

Keep DAM transformations and overlays when recreating a delivery relation - #1352

Merged
gabrielcld2 merged 2 commits into
developfrom
fix/preserve-dam-transformations
Nov 2, 2026
Merged

gabrielcld2 merged 2 commits into
developfrom
fix/preserve-dam-transformations

Conversation

@gabrielcld2

@gabrielcld2 gabrielcld2 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes transformations (crops and effects) applied in the DAM widget being lost for good when the asset is inserted into WordPress.

The issue

An asset inserted from the DAM with transformations stages them in post meta until it gets a delivery relation.

Delivery::create_size_relation() moves them into the new relationship row, and deletes the post meta.

Delivery::create_delivery() then restored the transformations it had captured before the row existed, which was nothing.

That restore goes through a relationship save that runs on shutdown, so it overwrote the migrated value with null.

With the post meta already deleted, the transformations couldn't be recovered without re-importing the asset.

Recreating an existing relation had a related issue: the capture merged the text and image overlays into the transformations string. The overlay columns were then dropped and the overlays ended up in transformations.

The solution

  • create_delivery() now reads transformations, text_overlay and image_overlay from the relationship data, each kept in its own column.
  • These values are passed to create_size_relation() through a new optional $preserve argument and written with the new row, instead of being restored afterwards. Transformations staged in post meta still take precedence. The other caller (class-assets.php) is unchanged.
  • Added tests/phpunit/tests/test-delivery-create-delivery.php. All 4 tests fail on develop and pass on this branch.
  • A separate commit removes internal ticket references from two existing test docblocks. This is unrelated but worth doing anyway for cleanliness.

QA notes

Prerequisites

  • A Gutenberg based WP site
  • Cloudinary plugin installed and configured
  • Cloudinary DAM extension enabled

Steps:

  1. In the block editor, add an Image block and open the media modal, then go to the Cloudinary tab (the DAM).
  2. Pick an image, apply a crop or an effect to it in the DAM (vie the "Edit" button), then insert it. The image shows in the editor with the transformations applied.
  3. In the block sidebar, under the Settings tab, toggle Overwrite Global Transformations, or pick a different Resolution.
    • On develop: the image loses the transformations.
    • On this branch: the image keeps the transformations.
  4. Publish the post and view it. On this branch, the image is delivered with the transformations.

Notes: to compare develop and this branch: go through all the steps on each branch, as the transformation is lost before the block sidebar changes. That setting change just helps confirm it.

…livery relation

An asset inserted from the DAM with a crop or effects stages those
transformations in post meta until it gets a delivery relation.
create_size_relation() moves them into the new row and deletes the post meta,
but create_delivery() then restored the transformations it had captured before
the row existed (none). The restore goes through a relationship save deferred
to shutdown, so it overwrote the migrated value with null and the
transformations were lost for good. The capture also came from
Relate::get_transformations(), which is memoized per request, so recreating the
relation again in the same request kept capturing the stale value.

Recreating an existing relation also baked its overlays into the
transformations column, as the capture merged them in, and dropped the overlay
columns.

Capture the transformations and overlays from the relationship data instead,
each in its own column, and write them with the new relation itself rather
than restoring them afterwards. Transformations staged in post meta still take
precedence.

@utkarshcloudinary utkarshcloudinary left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! ✅

@gabrielcld2
gabrielcld2 merged commit 25058eb into develop Nov 2, 2026
7 checks passed
This was referenced Nov 5, 2026
@gabrielcld2
gabrielcld2 deleted the fix/preserve-dam-transformations branch November 11, 2026 12:36
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.

3 participants