close
Skip to content

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

Open
Vrishabhsk wants to merge 1 commit intoWordPress:trunkfrom
Vrishabhsk:add/image-auto-attach
Open

Enhancement : Attach images to post uploaded in core/image block via media library#70313
Vrishabhsk wants to merge 1 commit intoWordPress:trunkfrom
Vrishabhsk:add/image-auto-attach

Conversation

@Vrishabhsk
Copy link
Copy Markdown
Contributor

What?

Why?

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

new-feature.mp4

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jun 4, 2025

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 <vrishabhsk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: Marc-pi <mdxfr@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>

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

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Feature] Media Anything that impacts the experience of managing media [Block] Image Affects the Image Block labels Jun 5, 2025
"@wordpress/date": "file:../date",
"@wordpress/deprecated": "file:../deprecated",
"@wordpress/dom": "file:../dom",
"@wordpress/editor": "14.24.0",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The editor package cannot be a dependency for block-library. Only packages that depend on it are edit-site and edit-post.

Copy link
Copy Markdown
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe something similar was resolved a couple of releases ago. The fix should be more general to the upload handler, instead of the Image block.

Core has more blocks that can upload and use images.

@Vrishabhsk
Copy link
Copy Markdown
Contributor Author

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

@Mamaduka
Copy link
Copy Markdown
Member

Mamaduka commented Jun 5, 2025

Thanks, @Vrishabhsk!

@Mamaduka
Copy link
Copy Markdown
Member

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

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

Labels

[Block] Image Affects the Image Block [Feature] Media Anything that impacts the experience of managing media [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image Block: When adding an existing image within a post, explore "attaching" the image to the post if it isn't already attached

3 participants