简体   繁体   English

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

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

I can see numerous examples on removing buttons in the tinymce editor but I want to do this for a custom editor I am adding from Javascript. 我可以看到许多有关在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;
}

There is no mention of editor ID here. 这里没有提及编辑器ID。 How do I do this only for a custom editor? 我该如何仅对自定义编辑器执行此操作? I dont want to change anything in the main editor shown in Wordpress post page. 我不想更改Wordpress帖子页面中显示的主编辑器中的任何内容。

The best and cleanest way is definitely to change your TinyMCE config before initialization. 最好和最干净的方法肯定是初始化之前更改TinyMCE配置。

Otherwise you can refer to my answer on another question where I set the editor in ReadOnly mode then enable just few buttons. 否则,您可以参考另一个问题的答案 ,即我将编辑器设置为只读模式,然后仅启用几个按钮。

I didn't test this code but your function should be something like this: 我没有测试此代码,但您的函数应如下所示:

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

For the list of commands, refer to this page 有关命令列表,请参阅此页面

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

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