Skip to content
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_meta_box breaks post preview #15404

Closed
braican opened this issue May 3, 2019 · 3 comments
Closed

add_meta_box breaks post preview #15404

braican opened this issue May 3, 2019 · 3 comments
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

Comments

@braican
Copy link

braican commented May 3, 2019

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:

  1. 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.

  2. In your active theme's functions.php file, add a simple call to add_meta_box:

    add_action('add_meta_boxes', function() {
      add_meta_box( 'test-meta-box', 'Testing meta boxes', function() {
        echo 'this is a test';
      });
    });
    
  3. 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):

07b5ac8423ae67207b1b0b0db17f59ca

Gif of uncommenting add_meta_box and trying to preview changes (preview not working as expected):

4e838c84ece7330d731356ad24367c2e

(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.

@ernilambar
Copy link
Member

This issue looks similar to #12617

@gziolo gziolo added [Feature] Meta Boxes A draggable box shown on the post editing screen [Type] Bug An existing feature does not function as intended Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Saving Related to saving functionality labels May 23, 2019
@spencerm
Copy link

spencerm commented Jun 4, 2019

It's the same as #14900 which was a fix to #12617

@braican
Copy link
Author

braican commented 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.

@braican braican closed this as completed Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

4 participants