Repository navigation
Editor: Skip auto-attaching media on save when attachment pages are enabled - #14308
faisalahammad wants to merge 1 commit into
Conversation
…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.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
andrewserong
left a comment
There was a problem hiding this comment.
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!
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
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
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
autoAttachMediaEnableddefault block editor setting inget_default_block_editor_settings(). It isfalsewhen thewp_attachment_pages_enabledoption is on, andtrueotherwise. Sites can still change it with theblock_editor_settings_allfilter.This backports WordPress/gutenberg#84851 (issue WordPress/gutenberg#84831). The auto-attach behavior came from WordPress/gutenberg#81977.
Testing
wp option update wp_attachment_pages_enabled 1.wp option update wp_attachment_pages_enabled 0and repeat. The image is now attached on save.Unit tests:
vendor/bin/phpunit tests/phpunit/tests/blocks/editor.phpTrac 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.