Skip to content

Media and Text: Add support for pattern overrides - #81280

Open
yashjawale wants to merge 4 commits into
WordPress:trunkfrom
yashjawale:feat/image-overrides-media-text-76408
Open

Media and Text: Add support for pattern overrides#81280
yashjawale wants to merge 4 commits into
WordPress:trunkfrom
yashjawale:feat/image-overrides-media-text-76408

Conversation

@yashjawale

Copy link
Copy Markdown
Contributor

What?

Part of #76408

This PR adds support for image overrides for Media & Text block (Does not cover the Cover block).

Why?

Pattern overrides weren't supported for Media & Text block and limited the number of layouts user could created. Enabling overrides for this block too increases the diversity of layouts that could be created.

How?

The attibutes were already marked as content attributes in block.json. This PR adds server side registrations for mediaUrl, mediaAlt, and mediaId as supported block-bindings attributes for core/media-text through the block_bindings_supported_attributes_core/media-text filter. (Later need to whitelist the attributes in wordpress-develop & then the use of this filter can be removed.)

In render_block_core_media_text(), resolve the bound values. Because WP_Block::replace_html() can't match the block's descendant selectors the callback finds the media figure with WP_HTML_Tag_Processor and either swaps src/alt on an existing img/video, or when the figure is empty (e.g. the pattern was saved without media), builds the media element from the resolved attributes and inserts it into the figure, then removes a temporary id used for targeting. A guard skips empty resolved URLs for the reset case.

Also adds test cases for checking the bindings. Although I'm not sure if I've used the right file for it. Happy to make any required changes.

Testing Instructions

  1. Create a synced pattern with a Media & Text block that has no image selected, add it to a post, and set an image override via the overrides controls.
  2. Confirm the overridden image shows in the post editor and on the frontend.
  3. Set an override on a Media & Text block, then reset the image in the pattern confirm the overridden image still renders in the editor and frontend.

Screenshots or screencast

Screen.Recording.2026-08-06.at.4.36.44.PM.mov

Use of AI Tools

Assisted by DeepSeek V4 Flash via OpenCode
All changes tested & reviewed manually.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Aug 6, 2026
@yashjawale

Copy link
Copy Markdown
Contributor Author

Will attach a backport once the changes are reviewed.

@yashjawale
yashjawale marked this pull request as ready for review August 6, 2026 11:53
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: yashjawale <yashjawale@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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

Labels

[Feature] Block bindings [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants