Remove submenu item in TinyMCE 4

I’m trying to remove a subitem from a TinyMCE dropdown toolbar button in WordPress.

The button is a plugin button (TinyMCE Table Button), and it inserts an item that allows the user to do CSS styling on the tables.

Read More

TinyMCE plugin generated dropdown

(Taulukon ominaisuudet == Table properties)

The toolbar button is created with

editor.addButton("table", {
    type: "menubutton",
    title: "Table",
    menu: menuItems
});

The menu item is created with

editor.addMenuItem('tableprops', {
    text: 'Table properties',
    context: 'table',
    onPostRender: postRender,
    onclick: dialogs.tableProps
});

editor is the TinyMCE plugins constructor param:

define("tinymce/tableplugin/Plugin", [
    "tinymce/tableplugin/TableGrid",
    ...
    "tinymce/PluginManager"
], function(TableGrid, Quirks, CellSelection, Dialogs, Tools, TreeWalker, Env, PluginManager) {
    var each = Tools.each;

    function Plugin(editor) {
        var clipboardRows, self = this, dialogs = new Dialogs(editor);

        ...

The editor has a function for addMenuItem, but I can’t find anything similar to removeMenuItem. I also tried to find the menu item inside the editor so I could remove it by hand, but the system is a bit shady as to where the buttons and menus are.

Is there a logical way of removing menu items in TinyMCE or will I have to remove it directly from the DOM after the editor has been generated?

Related posts

Leave a Reply

1 comment

  1. UPDATE: Just realize, you are using a different table plugin. I guess an easy way is to inspect the element/source and get the element ID of that menu item and use CSS to hide it.

    <style>
    #mceu_38 {display:none !important;}
    </style>
    

    Below is my original response, it is meant for editing the default menu bars


    You can customize the menu bar in the init function:

    tinymce.init({
        selector: "textarea",
        menu : { // this is the complete default configuration
            file   : {title : 'File'  , items : 'newdocument'},
            edit   : {title : 'Edit'  , items : 'undo redo | cut copy paste pastetext | selectall'},
            insert : {title : 'Insert', items : 'link media | template hr'},
            view   : {title : 'View'  , items : 'visualaid'},
            format : {title : 'Format', items : 'bold italic underline strikethrough superscript subscript | formats | removeformat'},
            table  : {title : 'Table' , items : 'inserttable deletetable | cell row column'},
            tools  : {title : 'Tools' , items : 'spellchecker code'}
        },    
        plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu paste"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
    });
    

    Just remove the items you don’t want in each menu property.

    Here’s an example with Table Properties removed:
    http://fiddle.tinymce.com/43eaab

    Here’s the documentation: http://www.tinymce.com/wiki.php/Configuration:menu

    gl.