-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rough POC of respecting "supports multiple" in the auto-inserted block metadata #53925
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/experimental/auto-inserting-blocks.php |
Something else we'd have to consider as a part of this stream is how to handle things if the block being inserted is already present in the content? I don't think the block should be auto-inserted in this case (when multiple:false). |
I remember we discussed during WC US that sometimes plugin developers would like to decide whether the block should get auto-inserted only once, but not necessarily in the first matching spot, but maybe last. I believe we should build a general function that performs basic checks informed by existing block API, and integrate a WP filter to offer ways to prevent insertion based on custom conditions. |
I like this approach, we would need to ensure there is any helpful context provided to the filter (outside of what may be exposed globally by WordPress to callbacks). |
I left a comment that contemplates on the complexity of adding support for |
To reduce clutter, I'm going to close this PR - it was always intended as a reference POC and has generated some useful discussion :) |
Thank you so much for starting this PR to gather all the insights. |
What?
A very rough proof of concept of having the new auto-insert block API (#51449) respect the supports multiple configuration in the
block.json
of the block configuring auto-insertion.This PR is definitely not ready for merge as is but could be shaped towards it.
Why?
There are cases where blocks are registered to have only one instance of the block in the layout and this is typically configured using the
supports.multiple
property inblock.json
. Currently, the auto-insertion does not respect this property and this PR demonstrates a potential path to doing so.An important caveat: this has no control over what instance of an anchor block the auto insertion will kick in. If the blocks has
supports.multiple
defined as false, then the block will only be inserted in the first instance of the anchor block.Testing Instructions
__experimentalAutoInsert
property inblock.json
supports.multiple
property inblock.json
is set to false.Testing Instructions for Keyboard
Screenshots or screencast