繁体   English   中英

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

[英]How to remove buttons in tinymce editor for the non-default wordpress editor

我可以看到许多有关在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帖子页面中显示的主编辑器中的任何内容。

最好和最干净的方法肯定是初始化之前更改TinyMCE配置。

否则,您可以参考另一个问题的答案 ,即我将编辑器设置为只读模式,然后仅启用几个按钮。

我没有测试此代码,但您的函数应如下所示:

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
    };
}

有关命令列表,请参阅此页面

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM