我使用以下命令来修剪TinyMCE编辑器
// Restrict buttons on the rich text editor
function formatTinyMCE($in)
{
$in[\'remove_linebreaks\'] = false;
$in[\'gecko_spellcheck\'] = false;
$in[\'keep_styles\'] = true;
$in[\'accessibility_focus\'] = true;
$in[\'tabfocus_elements\'] = \'major-publishing-actions\';
$in[\'media_strict\'] = true;
$in[\'paste_remove_styles\'] = true;
$in[\'paste_remove_spans\'] = true;
$in[\'paste_strip_class_attributes\'] = \'none\';
$in[\'paste_text_use_dialog\'] = true;
$in[\'wpeditimage_disable_captions\'] = true;
$in[\'plugins\'] = \'inlinepopups,tabfocus,paste,media,wordpress,wpeditimage,wpgallery,wplink,wpdialogs,infographic\';
$in[\'content_css\'] = get_template_directory_uri() . "/editor-style.css";
$in[\'wpautop\'] = true;
$in[\'apply_source_formatting\'] = false;
$in[\'theme_advanced_blockformats\'] = \'p,h3\';
$in[\'theme_advanced_buttons1\'] = \'formatselect,|,bold,italic,blockquote,|,link,unlink,|,bullist,numlist,infographic|,wp_fullscreen,wp_adv\';
$in[\'theme_advanced_buttons2\'] = \'pastetext,pasteword,removeformat,|,undo,redo\';
$in[\'theme_advanced_buttons3\'] = \'\';
$in[\'theme_advanced_buttons4\'] = \'\';
return $in;
}
add_filter(\'tiny_mce_before_init\', \'formatTinyMCE\' );
然后我有一个插件来创建一个额外的快捷键:
function fetchInfographic() {
return \'HERE BE THE INFOGRAPHIC\';
}
add_shortcode(\'infographic\', \'fetchInfographic\');
function addButton() {
if(current_user_can(\'edit_posts\') && current_user_can(\'edit_pages\'))
{
add_filter(\'mce_external_plugins\', \'addPlugin\');
add_filter(\'mce_buttons\', \'registerButton\');
}
}
add_action(\'init\', \'addButton\');
function registerButton($buttons) {
array_push($buttons, "infographic");
return $buttons;
}
function addPlugin($pluginArray) {
$pluginArray[\'infographic\'] = plugins_url(\'infographic_plugin.js\', __FILE__);
return $pluginArray;
}
(infographic\\u plugin.js)
(function() {
tinymce.create(\'tinymce.plugins.infographic\', {
init : function(ed, url) {
console.log(\'url\');
ed.addButton(\'infographic\', {
title : \'Add an infographic\',
image : url+\'/dashboard.png\',
onclick : function() {
ed.selection.setContent(\'[infographic]\');
}
});
},
createControl : function(n, cm) {
return null;
},
});
tinymce.PluginManager.add(\'infographic\', tinymce.plugins.infographic);
})();
如果删除formatTinyMCE函数,效果会很好,但是使用它时,按钮不会出现。正如您从函数中看到的,我尝试在[\'plugins\']中的$和[\'theme\\u advanced\\u buttons1\'中的$中添加“infographic”,但没有效果。