Skip to content

File Block: use inner block for Button #57314

Open

Description

@creativecoder

What problem does this address?

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.

Activity

  1. CoderAbhinav commented on Nov 2, 2026

    @CoderAbhinav

    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 UI control. Whether users can set it is a separate decision, which Force a download inside a link #11471 tracks.
    • 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.

    @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.

  2. CoderAbhinav commented on Nov 2, 2026

    @CoderAbhinav

    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 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:

    Image

    Feedback is welcome on two points:

    1. Is a new core source the right approach here? The name follows core/post-data and core/term-data.
    2. The PHP source needs a backport to WordPress core.
  3. t-hamano commented on Nov 2, 2026

    @t-hamano
    Contributor

    @CoderAbhinav Thanks for investigating!

    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.

  4. CoderAbhinav commented on Nov 2, 2026

    @CoderAbhinav

    Thanks @t-hamano, that's fair on both points.

    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:

    1. 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.
    2. 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?

  5. added
    [Status] In discussionUsed to indicate that an issue is in the process of being discussed
    on Nov 3, 2026
  6. t-hamano commented on Nov 9, 2026

    @t-hamano
    Contributor

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Block] FileAffects the File Block[Status] In ProgressTracking issues with work in progress[Status] In discussionUsed to indicate that an issue is in the process of being discussed[Type] EnhancementA suggestion for improvement.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions