Skip to content

Editor: Skip auto-attaching media on save when attachment pages are enabled - #14308

Closed
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:ticket/auto-attach-attachment-pages
Closed

faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:ticket/auto-attach-attachment-pages

Conversation

@faisalahammad

Copy link
Copy Markdown

When attachment pages are enabled, the block editor attaching an unattached image to the post on save moves its attachment page to a URL under that post. The old attachment page URL then returns a 404, so existing links and indexed URLs break.

This adds an autoAttachMediaEnabled default block editor setting in get_default_block_editor_settings(). It is false when the wp_attachment_pages_enabled option is on, and true otherwise. Sites can still change it with the block_editor_settings_all filter.

This backports WordPress/gutenberg#84851 (issue WordPress/gutenberg#84831). The auto-attach behavior came from WordPress/gutenberg#81977.

Testing

  1. Enable attachment pages: wp option update wp_attachment_pages_enabled 1.
  2. Upload an image in the Media Library so it is not attached to any post, and note its attachment page URL.
  3. Add the image to a post with an Image block and save the post.
  4. The image stays unattached, and the old attachment page URL still loads.
  5. Run wp option update wp_attachment_pages_enabled 0 and repeat. The image is now attached on save.

Unit tests: vendor/bin/phpunit tests/phpunit/tests/blocks/editor.php

Trac ticket: https://core.trac.wordpress.org/ticket/66321

Use of AI Tools

AI assistance: Yes. Tool: Claude Code. Used for drafting the patch, test, and PR text. I reviewed and tested the final code.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…nabled.

Attaching an image to a post moves its attachment page to a URL under that post, so the old attachment page URL returns a 404. This adds an `autoAttachMediaEnabled` default block editor setting that is false when the `wp_attachment_pages_enabled` option is on. Sites can still change it with the `block_editor_settings_all` filter.

Follow-up to the Gutenberg change in WordPress/gutenberg#84851.

See #66321.
@github-actions

Copy link
Copy Markdown

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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props faisalahammad.

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

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@andrewserong andrewserong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is testing well for me, and makes sense to explicitly set the default value here alongside the other block editor defaults!

Looking good to me, I can commit this later on today.

Thanks again for the fix!

wporg-sync pushed a commit that referenced this pull request Oct 16, 2026
The block editor attaches unattached images in Image and Gallery blocks to the post when the post is saved. When attachment pages are enabled, attaching an image moves its attachment page to a URL under that post, and
the old attachment page URL then returns a 404.

This adds an `autoAttachMediaEnabled` setting to `get_default_block_editor_settings()`. It is `false` when the `wp_attachment_pages_enabled` option is on, and `true` otherwise. Sites can still change it with the
`block_editor_settings_all` filter.

Developed in: #14308

Props faisalahammad, rejaulalomkhan, andrewserong, ramonopoly, padams.
Fixes #66321.



git-svn-id: https://develop.svn.wordpress.org/trunk@64385 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 64385
GitHub commit: 7d64ecf

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Oct 16, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 16, 2026
The block editor attaches unattached images in Image and Gallery blocks to the post when the post is saved. When attachment pages are enabled, attaching an image moves its attachment page to a URL under that post, and
the old attachment page URL then returns a 404.

This adds an `autoAttachMediaEnabled` setting to `get_default_block_editor_settings()`. It is `false` when the `wp_attachment_pages_enabled` option is on, and `true` otherwise. Sites can still change it with the
`block_editor_settings_all` filter.

Developed in: WordPress/wordpress-develop#14308

Props faisalahammad, rejaulalomkhan, andrewserong, ramonopoly, padams.
Fixes #66321.


Built from https://develop.svn.wordpress.org/trunk@64385


git-svn-id: http://core.svn.wordpress.org/trunk@63535 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants