-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block meta attributes and Custom Fields panel conflict #23078
Comments
A different issue, but the same problem was discussed in a slack triage session: I think the problem happens because there are two API requests happening in the background. One REST request to update the post, and that's followed by an ajax request to post.php to update metaboxes. My hunch is that the second request overwrites the values set by the first. I can think of two potential fixes:
Probably other options too. |
I came to the same conclusion trying to develop a generic post meta field block. Notes:
Are these fixes something that would be implemented by core or would each block have to do it? |
I'm thinking this would be in the Gutenberg codebase. This is where metabox saving happens: gutenberg/packages/edit-post/src/store/actions.js Lines 335 to 398 in 1f55df5
So that might be a place to investigate. |
EDIT: Please have a look at #23078 (comment) for a much better workaround.
|
getEditorSettings().enableCustomFields !== undefined, |
we can hide the setting like this:
add_filter('block_editor_settings_all', function ($editorSettings, $editorContext) ){
unset($editorSettings['enableCustomFields']);
return $editorSettings;
}, 10, 2);
Okay, scrap that, it is actually way easier. Just remove the meta box which also hides the settings panel. You can even do it just for those post types you want. Way better than what I had in #23078 (comment). 🤣
|
I found you can either prepend your meta key with an |
I tried this an I got an error that I'm not allowed to edit the field. Did I miss something? |
Nasty conflict, hard to troubleshoot. WordPress/gutenberg#23078
Turns out you also need to add |
I have started this pull request trying to solve this issue. Although I must say that I am not familiar with that code and I am not sure if that's a viable approach. |
Describe the bug
We have a block with an attribute, which saves in post meta. This block is working with no problem. Then we activate the Custom Fields panel and now changed in block attribute value will not be saved in post meta.
To reproduce
Steps to reproduce the behavior:
Create a block with meta attribute - https://developer.wordpress.org/block-editor/tutorials/metabox/meta-block-3-add/
Don't forget to register meta field in PHP - https://developer.wordpress.org/block-editor/tutorials/metabox/meta-block-2-register-meta/
Insert this block in the post, fill the text control and update the post
Make sure your meta value saved in post (reload the page and you will see this value in field)
Activate Custom Fields panel
Try to change the block value, then update the post and reload the page
You will see, that your new meta value was not saved
Expected behavior
Custom meta should be synchronized automatically when editing block attributes and editing Custom Fields panel.
Editor version:
Desktop:
Additional context
The text was updated successfully, but these errors were encountered: