0

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);
    }
}
7
  • wp_editor ( $content, 'custom_editor', array ( "media_buttons" => true ),); that comma looks odd at the end, what does the PHP error log say? – Q Studio Jan 27 at 21:36
  • @QStudio A comma at the end of an array doesn't cause any issues that I know of, but I deleted it. Good catch. But no change, and no errors reported. – Jeremy Caris Jan 27 at 21:46
  • if( 'post' == $_POST['post'] && !current_user_can( 'edit_post', $post_id ) ) { return; } - so, this reject if it IS a "post" and if the user CANT edit posts ? – Q Studio Jan 27 at 21:49
  • @QStudio another good catch. Updated to !== but still with the same issue. Even if I get rid of all the entire if isset section, it doesn't change anything. Besides, that only applies when the post is saved. It's still never displaying the content in the visual tab. I just integrated this github.com/CMB2/CMB2 and tried their wysiwyg field, same results. I'm thinking it's an issue with Wordpress/meta boxes. – Jeremy Caris Jan 27 at 21:58
  • 1
    @QStudio Confirmed Wordpress issue: core.trac.wordpress.org/ticket/52050 – Jeremy Caris Jan 28 at 0:35
1

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.

2
  • Thanks! Good to know. – Jeremy Caris Feb 2 at 2:14
  • You can also install the Classic Editor plugin to turn off Gutenberg, and then it works just fine also. – Jeremy Caris Feb 4 at 14:40
0

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

2
0

A temporary workaround that works for me is, make a 'text' mode default for wp-editor, like

// Set wp-editor in the 'Text' mode by default.
add_filter(
    'wp_default_editor',
    function () {
        return 'html';
    }
);

When we switch from text to visual, the wp-editor(tinyMCE) works fine, though its not a perfect fix but a quick win over adding a whole new plugin(Enable jQuery Migrate Helper).

1
  • Good news about this issue, soon the fix will be rollout by WP. The issue is closed, and on the way to release with WPv5.8 As per the roadmap, the WPv5.8 will be released by July 2021. – StarSagar Jun 9 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.