Switch to more specific hooks to render the Generate Image buttons to avoid conflicts#489
Conversation
…o ensure we don't render those in situations we don't want them: ''
|
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 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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #489 +/- ##
==========================================
Coverage 69.16% 69.16%
Complexity 981 981
==========================================
Files 63 63
Lines 4648 4648
==========================================
Hits 3215 3215
Misses 1433 1433
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ow hooks to inject our buttons instead of doing both on the editor.MediaUpload hook. This allows us to be more specific on where the buttons are being added and avoid having those render when they shouldn't. Ensure the media placeholder button still shows in the second position instead of first or last, requiring some extra code to handle that
jeffpaul
left a comment
There was a problem hiding this comment.
Testing via instructions and this works as expected, thanks!
What?
Closes #487
Switch to using
editor.MediaPlaceholderandeditor.MediaReplaceFlowas our hooks instead of usingeditor.MediaUploadWhy?
As reported in #487, there's some scenarios where the Generate Image button is rendering (like above the caption field when that field is selected) where we don't want it.
Seems that when using the
editor.MediaUploadhook to modify things, these sorts of "inline" components within an image block still show as being an image block even though they are nested within an image block.I originally had fixed this by checking for a specific prop that only existed on the main image block but that seemed pretty fragile long term. Switch instead to using more specific hooks to add our buttons, both the inline placeholder button and the menu button.
How?
editor.MediaUploadas our only hook and instead useeditor.MediaPlaceholderto add our button to the media placeholder andeditor.MediaReplaceFlowto add our button to the replace menuUse of AI Tools
AI assistance: Yes
Tool(s): Claude Code, Cursor
Model(s): Sonnet 4.6, GPT-5.5
Used for: Debugging and suggesting solutions. Review and testing of each suggestion done by me.
Testing Instructions
npm i && npm run buildGenerate ImagebuttonGenerate Imagebutton and that worksBlock fields: Show dataform driven inspector fields on blocks that support themexperiment. This will then show the caption field in the image block sidebar. Ensure no extra Generate Image button shows thereChangelog Entry