admin管理员组文章数量:1291343
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Share
Improve this question
edited Jan 27, 2021 at 22:33
Jeremy C.
asked Jan 27, 2021 at 21:23
Jeremy C.Jeremy C.
611 silver badge6 bronze badges
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 Commented Jan 27, 2021 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 C. Commented Jan 27, 2021 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 Commented Jan 27, 2021 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/CMB2/CMB2 and tried their wysiwyg field, same results. I'm thinking it's an issue with Wordpress/meta boxes. – Jeremy C. Commented Jan 27, 2021 at 21:58
- 1 @QStudio Confirmed Wordpress issue: core.trac.wordpress/ticket/52050 – Jeremy C. Commented Jan 28, 2021 at 0:35
3 Answers
Reset to default 1Just 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.
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).
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).
本文标签: wp editorwpeditor visual tab in meta box doesn39t show content
版权声明:本文标题:wp editor - wp_editor visual tab in meta box doesn't show content 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741516997a2382952.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论