如何删除tinymce编辑器中非默认wordpress编辑器的按钮

时间:2016-12-08 00:02:49

标签: javascript wordpress plugins tinymce

我可以看到很多关于在tinymce编辑器中删除按钮的例子,但我想为我从Javascript添加的自定义编辑器执行此操作。

function myplugin_tinymce_buttons( $buttons ) {
  //Remove the text color selector
  $remove = 'forecolor';

  //Find the array key and then unset
  if ( ( $key = array_search( $remove, $buttons ) ) !== false )
    unset( $buttons[$key] );

  return $buttons;
}

这里没有提到编辑ID。我如何仅为自定义编辑器执行此操作?我不想在Wordpress帖子页面中显示的主编辑器中更改任何内容。

1 个答案:

答案 0 :(得分:1)

最好和最干净的方法是在初始化之前更改你的TinyMCE配置

否则,您可以在另一个问题上参考my answer,我将编辑器设置为ReadOnly模式,然后只启用几个按钮。

我没有测试过这段代码,但你的功能应该是这样的:

function removeButton(editorId, pluginName, commandName) {
    var htmlEditorDiv = document.getElementById(editorId).previousSibling;
    var editor = tinymce.get(editorId);
    var buttonDiv = htmlEditorDiv.querySelectorAll('.mce-i-' + pluginName.toLowerCase())[0].parentElement.parentElement;
    buttonDiv.style.display = "none";
    buttonDiv.firstChild.onclick = function () {
        //Even if the button is invisible, it's better
        //removing the command associated to the button click just in case
    };
}

有关命令列表,请参阅this page