gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Enhancement : Attach images to post uploaded in core/image block via media library

Open Vrishabhsk opened this issue 6 months ago • 3 comments

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 uploadedTo media parameter
  • If not attached, when the post is saved / published the image will be attached to the post where its used.
  • When either the reset option in the core/image block is selected or the block is removed, the image is detached from the post.
  • The attachment/detachment process works via the WP REST API for attachments

Testing Instructions

  1. Add dummy images in the media library of your WP installation.
  2. Create a post and add an image block to it.
  3. Select the image via media library option.
  4. Save/Publish the post and go back to the media library.
  5. You will see the image attached to that post.
  6. 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

Vrishabhsk avatar Jun 04 '25 14:06 Vrishabhsk

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.

github-actions[bot] avatar Jun 04 '25 14:06 github-actions[bot]

Thanks for the review @Mamaduka, ill look for the blocks that have the media library handling and generalize this feature.

Vrishabhsk avatar Jun 05 '25 11:06 Vrishabhsk

Thanks, @Vrishabhsk!

Mamaduka avatar Jun 05 '25 12:06 Mamaduka

@Vrishabhsk, let's close this PR, since you're planning to explore an alternative solution.

Mamaduka avatar Jun 12 '25 08:06 Mamaduka