Skip to content

Skip source attachment edit root IDs on import - #270

Draft
ramonjd wants to merge 1 commit into
WordPress:masterfrom
ramonjd:skip/root-edit-attachment-meta
Draft

ramonjd wants to merge 1 commit into
WordPress:masterfrom
ramonjd:skip/root-edit-attachment-meta

Conversation

@ramonjd

@ramonjd ramonjd commented Oct 2, 2026

Copy link
Copy Markdown
Member

WordPress 7.2's attachment edit lineage work in WordPress/wordpress-develop#13303 adds _wp_attachment_edit_root_id: the attachment ID an edit chain started from, written when /wp/v2/media/<id>/edit creates a derivative attachment. This follows up on the importer question raised in review.

Add the key to the skip list in is_valid_meta_key(), alongside _wp_attached_file, _wp_attachment_metadata, and _wp_font_face_file, following the comment and skip-list change in #264.

The value is a source-site attachment ID. IDs are reassigned on import, so importing it unchanged can point at an unrelated attachment already on the destination. For example, a source root ID of 42 could identify somebody else's image on the destination even if the imported root becomes attachment 100. Consumers — the media editor's “Restore original image”, the REST edit_root field, and the wp:edit-root link — could then present that unrelated image as the original.

Skipping is safe because the feature records lineage going forward only and every consumer treats absent lineage as untracked. Unlike regenerated attachment metadata, this key is not regenerated after import: the lineage is simply severed. That is deliberately lossy, but permitted by the feature's design and safer than preserving an incorrect relationship.

Follow-up (not implemented here)

The lossless fix is to remap the ID like _thumbnail_id: collect it during postmeta import and rewrite it to a destination ID in remap_featured_images(). Remap when the root attachment is part of the same import and drop the meta when it is not. If that handling lands later, remove this key from the skip list.

Validation

  • PHP syntax check and git diff --check pass.
  • Direct is_valid_meta_key() smoke check passes for all five skipped keys and four preserved keys, including _thumbnail_id, image alt text, custom meta, and a similarly named key.
  • Don't import the _wp_font_face_file meta key #264 did not include a test; this follows its minimal production change. The full WordPress PHPUnit suite is left to CI, as documented in CONTRIBUTING.md; the local checkout has neither Composer dependencies nor the WordPress test environment.

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.

1 participant