Wp.editor.初始化不会显示相同的默认工具条

时间:2019-01-23 作者:J.BizMai

在我的插件的自定义帖子类型中,对于编辑帖子页面,metabox中有一个WP编辑器。在这个元数据库中,有一个通过jQuery和Ajax添加WP编辑器的按钮。我设法做到了,但是wp.editor.initialize( response.html.editor_id, { tinymce : true } ); 显示的默认工具栏与wp_editor(); 在php中,用于初始化第一个WP编辑器。

First WP Editor loaded by PHP

enter image description here

Second WP Editor loaded by jQuery

enter image description here

如何为每个tinymce获得相同的默认工具栏?

2 个回复
SO网友:Ravi Patel

请为wp的相同布局添加此代码

wp.editor.initialize(editor_id,{
    tinymce: {
      wpautop: true,
      plugins : \'charmap colorpicker hr lists paste tabfocus textcolor fullscreen wordpress wpautoresize wpeditimage wpemoji wpgallery wplink wptextpattern\',
      toolbar1: \'formatselect,bold,italic,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,wp_more,spellchecker,fullscreen,wp_adv,listbuttons\',
      toolbar2: \'styleselect,strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help\',
      textarea_rows : 20
    },
    quicktags: {buttons: \'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close\'},
    mediaButtons: false,
});

SO网友:Aftab Muni

您可以使用下面的代码作为完整的编辑器。(You have to make some changes by your own)

wp.editor.initialize ( \'EditorTextArea\' , {

tinymce: {
    wpautop: to true ,
    theme: \'modern\' ,
    skin: \'lightgray\' ,
    language: \'en\' ,
    formats: {
        alignleft: [
            {selector: \'p, h1, h2, h3, h4, h5, h6, td, th, div, ul, ol, li\' , styles: {textAlign: \'left\' }},
            {selector: \'img, table, dl.wp-caption\' , classes: \'alignleft\' }
        ],
        aligncenter: [
            {selector: \'p, h1, h2, h3, h4, h5, h6, td, th, div, ul, ol, li\' , styles: {textAlign: \'center\' }},
            {selector: \'img, table, dl.wp-caption\' , classes: \'aligncenter\' }
        ],
        alignright: [
            {selector: \'p, h1, h2, h3, h4, h5, h6, td, th, div, ul, ol, li\' , styles: {textAlign: \'right\' }},
            {selector: \'img, table, dl.wp-caption\' , classes: \'alignright\' }
        ],
        strikethrough: {inline: \'del\' }
    },
    relative_urls: false ,
    remove_script_host: false ,
    convert_urls: false ,
    browser_spellcheck: to true ,
    fix_list_elements: to true ,
    entities: \'38, amp, 60, lt, 62, gt \' ,
    entity_encoding: \'raw\' ,
    keep_styles: false ,
    paste_webkit_styles: \'font-weight font-style color\' ,
    preview_styles: \'font-family font-size font-weight font-style text-decoration text-transform\' ,
    tabfocus_elements: \': prev ,: next\' ,
    plugins: \'charmap, hr, media, paste, tabfocus, textcolor, fullscreen, wordpress, wpeditimage, wpgallery, wplink, wpdialogs, wpview\' ,
    resize: \'vertical\' ,
    menubar: false ,
    indent: false ,
    toolbar1: \'bold, italic, strikethrough, bullist, numlist, blockquote, hr, alignleft, aligncenter, alignright, link, unlink, wp_more, spellchecker, fullscreen, wp_adv\' ,
    toolbar2: \'formatselect, underline, alignjustify, forecolor, pastetext, removeformat, charmap, outdent, indent, undo, redo, wp_help\' ,
    toolbar3: \'\' ,
    toolbar4: \'\' ,
    body_class: \'id post-type-post-status-publish post-format-standard\' ,
    wpeditimage_disable_captions: false ,
    wpeditimage_html5_captions: true

},
Quicktags: true,
mediaButtons: true
})

您也可以查看此处:https://gist.github.com/rheinardkorf/aec4d46d3833d2f7a6a27c4481ba0b44

https://wp-kama.ru/question/wp-editor-initialize

如果您在这方面遇到任何问题,请告诉我。