1

I built a meta box where a click on a button shows a textarea with rich text editing enabled. After creating the textarea and appending it to the DOM, I run this to initialize the editor:

console.log(wp.editor.getDefaultSettings());
var settings = {
    tinymce: {toolbar1:"bold,italic,bullist,link"}
};
wp.editor.initialize( contentID, settings);

As a result the textarea appears and tinymce get intialized on it. The issue is that my custom settings have no effect. In the above example I still get the numlist button, whereas it isn't specified in the settings:

editor example

According to the documentation my own settings should be merged with default settings which seems to not happen as wp.editor.getDefaultSettings() returns:

{
   "tinymce":{
      "theme":"modern",
      "skin":"lightgray",
      "language":"fr",
      "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":true,
      "fix_list_elements":true,
      "entities":"38,amp,60,lt,62,gt",
      "entity_encoding":"raw",
      "keep_styles":false,
      "cache_suffix":"wp-mce-4800-20180716-tadv-4.7.13",
      "resize":"vertical",
      "menubar":false,
      "branding":false,
      "preview_styles":"font-family font-size font-weight font-style text-decoration text-transform",
      "end_container_on_empty_block":true,
      "wpeditimage_html5_captions":true,
      "wp_lang_attr":"fr-FR",
      "wp_keep_scroll_position":false,
      "wp_shortcut_labels":{
         "Heading 1":"access1",
         "Heading 2":"access2",
         "Heading 3":"access3",
         "Heading 4":"access4",
         "Heading 5":"access5",
         "Heading 6":"access6",
         "Paragraph":"access7",
         "Blockquote":"accessQ",
         "Underline":"metaU",
         "Strikethrough":"accessD",
         "Bold":"metaB",
         "Italic":"metaI",
         "Code":"accessX",
         "Align center":"accessC",
         "Align right":"accessR",
         "Align left":"accessL",
         "Justify":"accessJ",
         "Cut":"metaX",
         "Copy":"metaC",
         "Paste":"metaV",
         "Select all":"metaA",
         "Undo":"metaZ",
         "Redo":"metaY",
         "Bullet list":"accessU",
         "Numbered list":"accessO",
         "Insert/edit image":"accessM",
         "Remove link":"accessS",
         "Toolbar Toggle":"accessZ",
         "Insert Read More tag":"accessT",
         "Insert Page Break tag":"accessP",
         "Distraction-free writing mode":"accessW",
         "Keyboard Shortcuts":"accessH"
      },
      "content_css":"https://[redacted]/dev/www/core/wp-includes/css/dashicons.css?ver=4.9.8,https://[redacted]/dev/www/core/wp-includes/js/tinymce/skins/wordpress/wp-content.css?ver=4.9.8",
      "toolbar1":"bold,italic,bullist,numlist,link",
      "wpautop":false,
      "indent":true,
      "elementpath":false,
      "plugins":"charmap,colorpicker,hr,lists,paste,tabfocus,textcolor,fullscreen,wordpress,wpautoresize,wpeditimage,wpemoji,wpgallery,wplink,wptextpattern"
   },
   "quicktags":{
      "buttons":"strong,em,link,ul,ol,li,code"
   }
}

Any idea of what I may be doing wrong ?

1 Answer 1

1

Found: the settings have to have quicktags defined:

var settings = {
    tinymce: {toolbar1:"bold,italic,bullist,link"},
    quicktags: {
        "buttons": "strong,em,link,ul,li,code"
    }
};
wp.editor.initialize( contentID, settings);

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.