add_meta_box breaks post preview #15404
Labels
Backwards Compatibility
Issues or PRs that impact backwards compatability
[Feature] Meta Boxes
A draggable box shown on the post editing screen
[Feature] Saving
Related to saving functionality
[Type] Bug
An existing feature does not function as intended
Describe the bug
When adding a meta box via WordPress'
add_meta_box
function to any post type, it appears to break the previewing functionality of that post. When working off of a fresh installation, I'm able to add a new post or edit an existing post and use thePreview
button to preview my unsaved changes. However, when I add a meta box to a post using theadd_meta_box
function, clicking thePreview
button does not show my unsaved changes - it just shows the last saved version of the post.To reproduce
Steps to reproduce the behavior:
Go to any post on any theme that doesn't utilize
add_meta_box
with no plugins enabled, make a change to the content in the editor, and click preview. You should see the unsaved changes in the preview.In your active theme's
functions.php
file, add a simple call toadd_meta_box
:Go back to a post in WordPress and notice the new meta box below the Gutenberg editor. Now make a change to the title or content and click preview. If you're like me, you won't see those unsaved changes in the preview.
Expected behavior
I expect to see unsaved changes to my title and/or content appear when I view a preview of my post, while also being able to add any number of meta boxes to that post.
Screenshots
Gif of previewing a post with
add_meta_box
commented out (preview working as expected):Gif of uncommenting
add_meta_box
and trying to preview changes (preview not working as expected):(It happens fast, but you can see the
Testing meta boxes
meta box title at the bottom of the Gutenberg editor).This is happening both when I try using the Twenty Nineteen theme and when using our custom theme. The above tests are on a WordPress installation with no plugins installed or enabled.
Desktop (please complete the following information):
Additional context
This is on WordPress version 5.1.1.
In looking at the database after each of these test, it seems like when there's a call to
add_meta_box
, it prevents the creation of a new revision. In the first screencast, when the preview button works as expected, clicking the preview button creates a new entry in thewp_posts
table. In the second screencast and when a call toadd_meta_box
is being made, clicking the preview button does not create a new entry in thewp_posts
table.I discovered this while testing preview functionality with ACF. Basically adding a field group to any post type broke the preview in this way since ACF uses the
add_meta_box
function to create the field controls.The text was updated successfully, but these errors were encountered: