admin管理员组

文章数量:1122846

I've a custom post type in a custom plugin. In this post type, I am assigning a meta box field for some fixed hero content. This is just a textarea that I am applying tinymce to.

This works well, but I also need to support Gutenberg blocks for this post type. But when I add support for 'editor' for this post type it breaks the tinymce implementation for the custom meta box field.

tinymce displays and I can edit the "text" of the input field, but I cannot see, edit, or click into the tinymce "visual" editor. (The following image shows a textarea field that has text but is non-editable in the visual editor)

plugin.php:

function custom_post_type() {
  register_post_type('post_type_id',
    [
      'show_in_rest' => true,
      'supports' => ['editor'], <- editor breaks tinymce later
    ]
  );
}
add_action('init', 'custom_post_type');

function text_area_wysiwyg_script() {
  wp_enqueue_editor();
  wp_enqueue_script('text-area-wysiwyg', plugin_dir_url(__FILE__) . '/js/text-area-wysiwyg.js', [], '1.0', true);
}
add_action('admin_print_footer_scripts', 'text_area_wysiwyg_script');

text-area-wysiwyg.js:

jQuery(function textAreaToWysiwyg() {

  wp.editor.initialize("editor_id", {
    tinymce: {
      wpautop: true,
      plugins : '...',
      toolbar1: '...',
    },
    quicktags: true,
    mediaButtons: false
  });
});

In the JS file I've also tried:

tinymce.execCommand('mceAddEditor', true, 'editor_id');

How can I have both editor support (for Gutenberg blocks) and a custom meta field with tinymce in one post type?

本文标签: tinymcewpeditorinitialize() breaks when support for 39editor39 is added to custom post type