Repository navigation
Description
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 the Preview button to preview my unsaved changes. However, when I add a meta box to a post using the add_meta_box function, clicking the Preview 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_boxwith 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.phpfile, add a simple call toadd_meta_box:add_action('add_meta_boxes', function() { add_meta_box( 'test-meta-box', 'Testing meta boxes', function() { echo 'this is a test'; }); }); -
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):
- OS: Mac OSX 10.14.4
- Browser: Chrome
- Version: 73.0.3683.103
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 the wp_posts table. In the second screencast and when a call to add_meta_box is being made, clicking the preview button does not create a new entry in the wp_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.


Activity
ernilambar commentedon May 3, 2019
This issue looks similar to #12617
spencerm commentedon Jun 4, 2019
It's the same as #14900 which was a fix to #12617
braican commentedon Jun 4, 2019
Updating to WordPress 5.2 fixed this specific issue, as that release included the fix in #14877. The issue regarding metaboxes not being previewable still persists, however, and is being tracked now in #14900. I'll close this in favor of that issue.