You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As mentioned in #52850, the File Block button is a kind of orphan in term of styling. It will inherit global button colors, but otherwise can't be style from the Global Styles UI.
What is your proposed solution?
Update the File Block to use a inner Button Block. This way Button Block styles can be used to modify the File Block's button.
I'd like to pick this up again, based on the work and the review feedback in #68510.
The earlier review had three main points: existing File blocks broke because there was no deprecation, the download change on the Button block was mixed into the same PR, and the PR was too large. To address them, I propose two smaller PRs:
PR 1: Button, add a download attribute
A boolean attribute, sourced from the download HTML attribute of the link (the same pattern as the Video block autoplay attribute).
No deprecation is necessary. Existing buttons have no download attribute, so their saved markup does not change. Fixtures confirm this.
PR 2: File, use an inner Buttons > Button block for the download button
The File block saves a locked core/buttons > core/button with download, in place of the hand-written <a class="wp-block-file__button">. Button block styles from Global Styles then apply to it.
A deprecation with migrate on every existing File deprecation moves the old button text and URL into the inner Button block. Old content stays valid, with or without a custom button text, and with the button turned off.
When the user replaces the file, the inner button URL changes too.
render_block_core_file adds aria-describedby to the inner button link, so the link to the file name stays accessible.
The .wp-block-file__button CSS stays for posts that are not saved again. Themes that style .wp-block-file__button do not style new File blocks, so this needs a dev note.
While testing, I found a gap: templateLock: 'all' locks the inner Buttons > Button structure, but not the Button attributes. A user could unlink the download button, or link it to a different file than the one the File block shows.
To fix this, #86163 now binds the inner Button url to the File href through a new read-only Block Bindings source, core/file-data:
The File block provides href as the core/file-href context, and the source reads it in the editor and on the server.
The source has no setValues, so the Button hides its link controls. This uses the existing Button behavior for read-only bindings, so the Button block does not need to know about the File block.
The source is not listed in the bindings UI for other blocks.
The PHP callback sanitizes the URL, because core does not escape bound attribute values.
The PR also fixes a small Button bug: "Reset all" and the unlink shortcut cleared a URL that a binding locks.
The inner blocks in List View, with the lock:
Feedback is welcome on two points:
Is a new core source the right approach here? The name follows core/post-data and core/term-data.
The PHP source needs a backport to WordPress core.
While testing, I found a gap: templateLock: 'all' locks the inner Buttons > Button structure, but not the Button attributes. A user could unlink the download button, or link it to a different file than the one the File block shows.
Isn't this the expected behavior? templateLock: 'all' prevents blocks from being inserted, removed, or moved. It doesn't prevent editing the content or data inside those blocks.
Moreover, the fact that converting the File block to use inner blocks forces us to keep the file URL in sync seems to me to be exactly the evidence that inner blocks aren't a good fit for the File block.
On templateLock: agreed, that's the expected behavior. I didn't mean that templateLock is wrong. I meant that once the button is an inner block, the file URL lives in two places, and the PR has to handle that.
On whether inner blocks are a good fit: I see the cost. The reason I still went this way is styling. With on-demand block assets (the default for block themes), the Global Styles for core/button print only when a Button block renders (wp_add_global_styles_for_blocks()). So a File block that only reuses the Button classes doesn't get the Button styles on a page without another Button block. A real inner Button is what makes the styles from #57314 apply reliably.
The alternatives I see without inner blocks:
Keep the current markup and let the File button be styled through styles.blocks.core/file.elements.button. This works in theme.json today, but it isn't in the Global Styles UI, and the button doesn't follow the Button block styles.
Expose the File button in the Global Styles UI under the File block. This fixes the UI gap, but it's a separate style surface that users must keep in line with the Button block.
If you think the sync cost outweighs the styling benefit, I'm happy to close #86163 (and #86162) and explore option 2 instead. Which direction would you prefer?
The reason I still went this way is styling. With on-demand block assets (the default for block themes), the Global Styles for core/button print only when a Button block renders (wp_add_global_styles_for_blocks()). So a File block that only reuses the Button classes doesn't get the Button styles on a page without another Button block. A real inner Button is what makes the styles from #57314 apply reliably.
If users want to style the button inside the File block via the Global Styles UI, they can use Elements > Buttons, which is always loaded regardless of on-demand block assets. Is there a specific reason you want the File button to follow the core/button styles rather than the button element styles?
Activity
CoderAbhinav commentedon Nov 2, 2026
I'd like to pick this up again, based on the work and the review feedback in #68510.
The earlier review had three main points: existing File blocks broke because there was no deprecation, the
downloadchange on the Button block was mixed into the same PR, and the PR was too large. To address them, I propose two smaller PRs:PR 1: Button, add a
downloadattributedownloadHTML attribute of the link (the same pattern as the Video blockautoplayattribute).downloadattribute, so their saved markup does not change. Fixtures confirm this.PR 2: File, use an inner Buttons > Button block for the download button
core/buttons>core/buttonwithdownload, in place of the hand-written<a class="wp-block-file__button">. Button block styles from Global Styles then apply to it.migrateon every existing File deprecation moves the old button text and URL into the inner Button block. Old content stays valid, with or without a custom button text, and with the button turned off.render_block_core_fileaddsaria-describedbyto the inner button link, so the link to the file name stays accessible..wp-block-file__buttonCSS stays for posts that are not saved again. Themes that style.wp-block-file__buttondo not style new File blocks, so this needs a dev note.@t-hamano @carolinan @fabiankaegy does this direction look right to you? I will open PR 1 as a draft now, and PR 2 after it.
CoderAbhinav commentedon Nov 2, 2026
An update on #86163.
While testing, I found a gap:
templateLock: 'all'locks the inner Buttons > Button structure, but not the Button attributes. A user could unlink the download button, or link it to a different file than the one the File block shows.To fix this, #86163 now binds the inner Button
urlto the Filehrefthrough a new read-only Block Bindings source,core/file-data:hrefas thecore/file-hrefcontext, and the source reads it in the editor and on the server.setValues, so the Button hides its link controls. This uses the existing Button behavior for read-only bindings, so the Button block does not need to know about the File block.The inner blocks in List View, with the lock:
Feedback is welcome on two points:
core/post-dataandcore/term-data.t-hamano commentedon Nov 2, 2026
@CoderAbhinav Thanks for investigating!
Isn't this the expected behavior?
templateLock: 'all'prevents blocks from being inserted, removed, or moved. It doesn't prevent editing the content or data inside those blocks.Moreover, the fact that converting the File block to use inner blocks forces us to keep the file URL in sync seems to me to be exactly the evidence that inner blocks aren't a good fit for the File block.
CoderAbhinav commentedon Nov 2, 2026
Thanks @t-hamano, that's fair on both points.
On
templateLock: agreed, that's the expected behavior. I didn't mean thattemplateLockis wrong. I meant that once the button is an inner block, the file URL lives in two places, and the PR has to handle that.On whether inner blocks are a good fit: I see the cost. The reason I still went this way is styling. With on-demand block assets (the default for block themes), the Global Styles for
core/buttonprint only when a Button block renders (wp_add_global_styles_for_blocks()). So a File block that only reuses the Button classes doesn't get the Button styles on a page without another Button block. A real inner Button is what makes the styles from #57314 apply reliably.The alternatives I see without inner blocks:
styles.blocks.core/file.elements.button. This works in theme.json today, but it isn't in the Global Styles UI, and the button doesn't follow the Button block styles.If you think the sync cost outweighs the styling benefit, I'm happy to close #86163 (and #86162) and explore option 2 instead. Which direction would you prefer?
t-hamano commentedon Nov 9, 2026
If users want to style the button inside the File block via the Global Styles UI, they can use Elements > Buttons, which is always loaded regardless of on-demand block assets. Is there a specific reason you want the File button to follow the
core/buttonstyles rather than the button element styles?