Enhancement : Attach images to post uploaded in core/image block via media library
What?
- Closes : https://github.com/WordPress/gutenberg/issues/66663
- Attach image to post that is uploaded in core/image block via media library option.
- Detach the image when the block is removed or the reset option is selected.
Why?
- https://github.com/WordPress/gutenberg/issues/66663
- Images are not attached to the post when they are added via the media library option in the core/image block.
- The attachment only happens when the image is uploaded while the user is in editing a post.
How?
- Evaluate if the attachment is already attached to another post via its
uploadedTomediaparameter - If not attached, when the post is
saved / publishedthe image will be attached to the post where its used. - When either the
resetoption in the core/image block is selected or the block is removed, the image is detached from the post. - The
attachment/detachmentprocess works via theWP REST APIforattachments
Testing Instructions
- Add dummy images in the media library of your WP installation.
- Create a post and add an image block to it.
- Select the
imageviamedia libraryoption. - Save/Publish the post and go back to the
media library. - You will see the image attached to that post.
- If you remove the block or click the reset option in the core/image block, the image will be detached from the post.
Testing Instructions for Keyboard
Screenshots or screencast
https://github.com/user-attachments/assets/99c722cc-2183-4931-8761-b03cc19aaef8
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: Vrishabhsk <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: Marc-pi <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: andrewserong <[email protected]>
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.
Thanks for the review @Mamaduka, ill look for the blocks that have the media library handling and generalize this feature.
Thanks, @Vrishabhsk!
@Vrishabhsk, let's close this PR, since you're planning to explore an alternative solution.