Meta box html is not updating after saving


I have some meta boxes setup, some are my own, some are initialized in plugins.

As the title indicates, these meta boxes are not updating graphically after the post has been submitted.

Here’s an example of the problem, I have a metabox with a single toggle to enable notifications.
After the first notification is sent and the post has been published, I unset the checkbox and add a little warning above it.
However, this doesn’t update until I refresh the page entirely.

I’m fairly new to wordpress but this does not seem like the correct behaviour, as when I debug the code I can verify that the metabox callback is getting called after save_post.

I can also see by viewing the Network tab in Chrome’s Dev Tools, that when I ‘save_post’, it downloads a load of re-generated HTML with all the metaboxes updated. However I see no evidence of these elements updating in the editor.

I suspect it might be due to a quirk in the new editor.

It appears to be happening with all meta boxes, except funnily enough the featured image – I’ve got it set up so if there’s no _thumbnail_id set then it sets one by default, and after saving the post this image appears in the featured image box.

function cabtv_add_post_options()
    // Add our meta box for the "post" post type (default)
    if ( current_user_can("send_notifications") ) {
        $post_types = ["post", "go_live"];
        foreach ($post_types  as $post_type) {
add_action('admin_init', 'cabtv_add_post_options');

function cabtv_notif_on_post_html_view($post)
    //wp_nonce_field( 'cabtv_notif_metabox', 'cabtv_notif_metabox' );
    $checked = cabtv_should_post_send_notification($post);

    if ( get_post_meta( $post->ID, 'cabtv_notifications_sent', true ) == "1" ) { ?>
        <div style='padding:10px;'><span style='color:red; font-weight:bold;'>Notifications have already been sent for this post.</span></div>
    <?php } ?>

    <input type="hidden" name="cabtv_meta_box_present" value="true"></input>
    <input type="checkbox" name="cabtv_send_notification" value="true" <?php if ($checked) echo 'checked'; ?>></input>
    <?php echo esc_attr('Send notification on '.($post->post_status === 'publish' ? 'update' : 'publish') ); ?>

Some help would be appreciated.

, , hedgehog90 4 years 2020-02-25T08:38:38-05:00 0 Answers 73 views 0

Leave an answer