-
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
Prevent specific block from removing #16364
Comments
Hey @woorise! There's no API that lets third parties disable the Remove Block option for a specific block. There is, however, Templates which lets you specify which blocks should be in a post by default and lock them down so that the user can't add/remove any further blocks. Does that cover your use case? If not, could you go into some detail on what you're trying to accomplish? |
I tried the Templates and more specifically the PHP locking snippet with the "insert" option to lock a specific block but it doesn't allow me to insert any other block (different type). Is this the default behavior? |
Yes that's right, template locking prevents both insertion and deletion. I don't think it makes sense to allow one without the other. For example, if a user can insert blocks but not delete them, how can they remove blocks that are accidentally inserted? Could you go into some detail on what you're trying to accomplish? |
Template locking prevents insertion and deletion for a specific block or for all blocks? These are my requirements:
|
Thanks for the extra info, @woorise! Right now a developer can prevent the user from inserting and deleting all blocks using template locking, but it is not possible to disable inserting and deleting a specific block. Potentially we could do this by adding |
Great! This would be a highly welcomed addition. |
If you want to make sure that you can't remove a specific block (
This code will make sure that at least one block with the name Also check: https://bdwm.be/gutenberg-prevent-specific-block-from-being-removable/ |
@pwkip Thanks for the workaround. But still, it would be nice to have some officially supported block setting for that. Btw I think that in your fix might be an issue with nested blocks. Some block (e.g. You can use this function for searching for a block.
|
Hello support team, |
Hey folks! I'm coming to the party late on this issue but with some good news. A few releases ago the ability to lock blocks was implemented (locking for both removal and movement): https://developer.wordpress.org/block-editor/how-to-guides/curating-the-editor-experience/block-locking/ This is your best bet for implementing this. This allows other blocks to be implemented and, depending on how you set it up, allows for movement of the block even if you can't delete. I'm going to close this out as a result but, if I've gotten anything wrong here or if anything is missing, please let me know and we can reopen to continue the discussion. |
I'm inserting a block programmatically and I want to prevent users from removing it. Is there any way to disable the "Remove Block" option for a specific block?
The text was updated successfully, but these errors were encountered: