Repository navigation
Media & Text: Keep image size and URL in sync when selecting media - #84698
Mustafabharmal wants to merge 2 commits into
Conversation
🤖 PR meta 🤖🎉 PropsUnlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @hazardawareness, @DDadam21, @viktory-tori. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Updated as activity occurs, without notifying anyone named here. Add the 🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
What?
Fixes #38520.
When an image is selected in the Media & Text block, the image URL, the Resolution control and the
size-*class now always match.Why?
When an image was selected, the block always used the "large" URL but never stored
mediaSizeSlug. The Resolution control and the savedsize-*class fall back tofull, so the sidebar showed "Full Size" while the front end rendered the large image. To get the real full-size image, users had to pick another size and then switch back. AmediaSizeSlugalready set on the block (for example in a pattern) was also ignored, and the site's default image size setting was not respected.How?
In
attributesFromMedia(), the size is now chosen in this order, the same way the Image and Cover blocks do it:mediaSizeSlug, if the image has that size.imageDefaultSizeeditor setting (largeby default).full.The image URL comes from that size, and the size is stored in
mediaSizeSlug. Videos are unaffected.saveoutput is unchanged, so no deprecation is needed, and the default stayslarge, so performance is the same.Testing Instructions
"mediaSizeSlug":"large", an imagesrcending in-1024x…and the classsize-large.size-large.size-fullclass are used.<!-- wp:media-text {"mediaSizeSlug":"thumbnail"} --><div class="wp-block-media-text is-stacked-on-mobile"><figure class="wp-block-media-text__media"></figure><div class="wp-block-media-text__content"></div></div><!-- /wp:media-text -->, select an image, and confirm the thumbnail is used.Use of AI Tools
I used Claude Code to look into the cause and draft the change and this description. I reviewed and tested the change myself.