Question

If you click on the Text tab, you can see the content, but when you switch back to the Visual tab, it displays nothing. It's not white text on white background either... it just has no content. The functionality works otherwise. I can enter or change content via the Text tab, and that works. But it never shows the content in the Visual tab.

I have disabled all plugins and switched to the 2020 theme, running on Wordpress 5.6 on my local machine, same results. Here's my test code:

add_action('admin_init', 'custom_editor_meta_box');
function custom_editor_meta_box () {    
    add_meta_box ( 'custom-editor', 'Custom Editor', 'custom_editor_callback', 'post',);
}

function custom_editor_callback ( $post ) {          
    $content = get_post_meta($post->ID, 'custom_editor', true);

    wp_editor ( $content, 'custom_editor', array ( "media_buttons" => true ),);
}

add_action('save_post', 'custom_editor_save_postdata');
function custom_editor_save_postdata ( $post_id ) {
    if( isset( $_POST['custom_editor_nonce'] ) && isset( $_POST['post'] ) ) {
        if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return;
        } 

        if ( !wp_verify_nonce ( $_POST['custom_editor_nonce'] ) ) {
            return;
        } 

        if( 'post' == $_POST['post'] && !current_user_can( 'edit_post', $post_id ) ) {
            return;
        } 
    } 

    if ( !empty( $_POST['custom_editor'] ) ) {
        $data = $_POST['custom_editor'];
        update_post_meta($post_id, 'custom_editor', $data);
    }
}

enter image description here

enter image description here

Updated test code (still same results):

function custom_editor_meta_box () {    
    add_meta_box ( 'custom-editor', 'Custom Editor', 'custom_editor_callback', 'post',);
}

function custom_editor_callback ( $post ) {          
    $content = get_post_meta($post->ID, 'custom_editor', true);

    wp_editor ( $content, 'custom_editor', array ( "media_buttons" => true ) );
}

add_action('save_post', 'custom_editor_save_postdata');
function custom_editor_save_postdata ( $post_id ) {
    if ( !empty( $_POST['custom_editor'] ) ) {
        $data = $_POST['custom_editor'];
        update_post_meta($post_id, 'custom_editor', $data);
    }
}
Was it helpful?

Solution

The issue appears to be a bug with Wordpress 5.6. See this thread of comments for the same issue with the CMB2 "developer's toolkit for building metaboxes, custom fields, and forms," which I implemented as an alternative to try (it produced the same results I get with the original code I posted).

OTHER TIPS

Just want to add in case anyone needs a quick temporary patch before the next WP core release: I found installing the Enable jQuery Migrate Helper plugin solved it for several of my custom meta boxes. Obviously not a long term solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top