如果单击“文本”选项卡,您可以看到内容,但当切换回“视觉”选项卡时,它不会显示任何内容。它也不是白色背景上的白色文本。。。它只是没有内容。该功能在其他情况下工作。我可以通过文本选项卡输入或更改内容,这很有效。但它从不在可视选项卡中显示内容。
我禁用了所有插件并切换到2020主题,在本地机器上运行Wordpress 5.6,结果相同。以下是我的测试代码:
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);
}
}
更新的测试代码(结果仍然相同):
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);
}
}