Repository navigation
Declare files fields as attachment IDs in wp bs wpml config - #134
Merged
dnnsjsk merged 1 commit intoOct 19, 2026
Merged
Conversation
Files fields store attachment IDs. The generator now declares them with type="post-ids" and sub-type="attachment", with a "*" level for fields with multiple, so WPML replaces each ID with the attachment of the page language on render_block_data. Blocks whose only declared fields are files keep translate="0" and carry the ID keys, since WPML reads ID keys regardless of translate. A files field and a field of another type on one storage key are reported as a conflict.
This was referenced Oct 17, 2026
Contributor
|
Merged and released in 7.7.5 (86a311c1). Generated WPML configuration now declares files fields as attachment IDs, including multiple files, nested fields, and blocks with no translatable text. Regenerate your configuration with Regression coverage and full CI passed. |
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.
wp bs wpml config(7.7.4) treatsfilesas a value type, so WPML copies the stored attachment ID into the translation unchanged and every language shows the original attachment, including its alt text.WPML documents a declaration for IDs inside block attributes: a key with
type="post-ids"and asub-type, hereattachment(section "Automatically Converting IDs in Blocks" in Make Custom Gutenberg Blocks Translatable). WPML then replaces each ID with the attachment of the page language onrender_block_data, and keeps the original ID when there is no translated attachment. With WPML Media Translation, a translated image has its own alt text.What Blockstudio stores
filesfield stores the attachment ID ("image":173), withmultiplea list ("gallery":[64,99]). The editor writes IDs only (files.tsxonSelect,MediaPlaceholderlikewise);returnFormatandreturnSizeonly change whatBlock::render()hands to the template.multiplestores the ID itself, not a list, when one file is selected (media.length === 1 ? change(media[0].id)). In WPML 5.1.0,BlockAttributes::convertByPath()converts a scalar at the end of a path, and at a*level it converts both the entries of a list and a scalar. Somultiplegets a*level, which covers both, and a single field gets a plain key.<id>__sizeand stays undeclared.Changes
filesis no longer a value type. A files field becomes<key name="image" type="post-ids" sub-type="attachment" />, withmultiple<key name="gallery"><key name="*" type="post-ids" sub-type="attachment" /></key>. Group prefixes and repeater rows work as for text fields. ID keys get nolabel, because WPML does not offer them for translation.translatesays (WPML_Gutenberg_Config_Option::update_from_config(); the example in the WPML docs usestranslate="0"too). A block whose only declared fields are files keepstranslate="0"and carries the ID keys inside the entry, so WPML still offers nothing from it for translation. It counts as a block without text fields in the CLI summary.multipleon either, the key gets the*level). A files field and a field of another type (such asselectortext), or a hidden files field, are reported inconflictsand not declared. Hidden files fields are not declared, like every hidden field.dev/wpml(example, table, translate="0" note, conflict rule) anddev/cli;includes/llmregenerated. No changelog entry.Output for a sample block
{ "name": "my-theme/cards", "blockstudio": { "attributes": [ { "id": "heading", "type": "text", "label": "Heading" }, { "id": "gallery", "type": "files", "label": "Gallery", "multiple": true }, { "id": "cards", "type": "repeater", "label": "Cards", "attributes": [ { "id": "title", "type": "text", "label": "Title" }, { "id": "image", "type": "files", "label": "Image" } ] } ] } }Before,
galleryandimagehad no keys. Now:A block with only a files field (and value fields) changes from
<gutenberg-block type="..." translate="0" />to atranslate="0"entry with the ID keys.On the test theme (199 blocks), the generated file changes only by adding ID keys (58 keys); 88 blocks with text and 111 without stay the same, and the skipped and conflicts lists are unchanged.
Tests
WpmlConfigTest: new cases for single, multiple, group prefix, repeater rows, nested multiple in rows and hidden files; a block with only files fields (translate="0"with keys, valid document); files against files with and withoutmultiple, files against select, text and hidden files, in the block, in extensions and in repeater rows. The attribute builder check now compares text and files paths (multiplefrom the registered attribute). Three existing expectations changed where they contained files fields.WpmlConfigFilesRenderPathsTest: registers a block with single, multiple and repeater files fields throughBuild::init(), takes the ID paths from the generated configuration, converts the IDs onrender_block_datathe way WPML 5.1.0BlockAttributes::convertByPath()walks a path, and renders throughdo_blocks(). The template receives the converted IDs for a single field, a list, rows, and a multiple field that stores one ID.Results (WordPress Playground, PHP 8.3, WordPress 7.1.3, PHPUnit run inside a request,
tests/unit/wpml):tests/unit/extensions(61 OK),tests/unit/field(123 OK),tests/unit/attribute-builder(93 OK),tests/unit/cli(1 OK).Other checks:
composer csclean, PHPStan level 3 on the changed classes without errors,scripts/check-docs-content.mjsvalid.wp bs wpml configrun in Playground on the test theme. On a production theme with 25 Blockstudio blocks, the generated ID keys are identical to a hand-maintainedwpml-config.xmlthat has been verified with WPML 5.1.0 and WPML Media Translation.