-
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
Add hook for block deletion so post meta can be removed #5626
Comments
I would like to add importance to this issue. We are using blocks to control the existence of certain metadata (e.g. control template pieces outside of 'the_content()') AFAIK there is currently no way to force the existance of a certain block, so the the problem is that we will have metadata existing without an interface to edit them. That is less than optimal. |
https://gist.github.com/Luehrsen/41d27f30eaca2d997a84898271c004c7 This is my current implementation. It works, but it has some issues. Sometimes the actions fire twice, sometimes I get a strange error from the rest API. (See screenshot) But so far I am quite happy with the progress. |
Re-titled issue as "Add hook for block deletion so post meta can be removed" to clarify its direction. |
To me, ideally this is not something which occurs in the editor itself, as it's very possible someone may remove the block without interfacing with Gutenberg (by database, or |
Any updates on this? |
As a workaround of this I used |
Indeed, it makes a lot of sense what @aduth shared. Even if we would land #7325 proposed by @Luehrsen, this issue would still be present if someone uses REST API to remove one of the blocks. Given that mobile team is working on Gutenberg integration for the mobile app this issue will become even more prominent. I'm wondering if the root issue shouldn't be moved to WordPress core now as the logic for saving blocks is there. |
I'm going to close this now as a potential solution for this can't come from the block editor itself. |
Issue Overview
When you create a block that have a attribute set as
meta
, Gutenberg saves this same attribute as post meta, which is expected. However, if you remove the block and save the post, the post meta is still stored on the database.Steps to Reproduce (for bugs)
source: 'meta'
.get_post_meta
, the value of the post meta from that specific block.Expected Behavior
When the block is deleted, the post meta should be deleted as well. Unless there is another block of the same type for the post. On this case, post meta should be treated on a block basis, not on a post basis (related to #5599)
Current Behavior
Post meta is stored when you add one block, changes when you change the attribute on any instance of the block for the respective post, but it is not removed from the database if you remove all block instances.
Related Issues and/or PRs
#5599
The text was updated successfully, but these errors were encountered: