如何在wordpress中为插件添加fullpage tinymce插件到标准的tinymce编辑器?

时间:2014-05-27 18:02:30

标签: wordpress plugins tinymce-4 wordpress-3.9

我想使用标准的tinymce安装中通常包含的tinymce fullpage插件。

添加tinymce整页插件我尝试添加以下内容:

<?php
    function myformatTinyMCE($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']=false;
         $in['paste_remove_styles']=false;
         $in['paste_remove_spans']=false;
         $in['paste_strip_class_attributes']='none';
         $in['paste_text_use_dialog']=true;
         $in['wpeditimage_disable_captions']=true;
         $in['plugins']='tabfocus,paste,media,fullscreen,wordpress,wpeditimage,wpgallery,wplink,wpdialogs,wpfullscreen';

         $in['wpautop']=true;
         $in['apply_source_formatting']=false;
         $in['toolbar1']='bold,italic,strikethrough,bullist,numlist,blockquote,hr,alignleft,aligncenter,alignright,link,unlink,wp_more,spellchecker,wp_fullscreen,wp_adv ';
         $in['toolbar2']='formatselect,underline,alignjustify,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help ';
         $in['toolbar3']='';
         $in['toolbar4']='';
         return $in;
    }
    $settings = array('textarea_name'=>'template');
    wp_editor( get_option('html_template'), 'htmlemaileditor', $settings );
?>

然而,经过检查,这样做使得tinymce正在寻找一个不存在天真的tinymce位置的tinymce fullpage插件(/wp-includes/js/tinymce/plugins/fullpage/plugin.min.js)。

然后我尝试下载tinymce并解压缩fullpage插件目录并将该插件放在我的wordpress插件中,我在路径/fullpage_plugin/plugin.min.js创建。然后我尝试引用它执行以下操作:

<?PHP
add_filter('mce_external_plugins', 'myplugin_register_tinymce_javascript');

function myplugin_register_tinymce_javascript($plugin_array) {
   $plugin_array['myplugin'] = plugins_url('/fullpage_plugin/plugin.min.js',__file__);
   return $plugin_array;
}
?>

确实看到了这个文件,但是由于某种原因,tinymce仍在寻找插件(/wp-includes/js/tinymce/plugins/fullpage/plugin.min.js

那里的任何人都可能知道为wordpress 3.9.1附带的标准tinymce wp_editor启用全页支持的正确方法吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

按照wordpress codex中的示例,我替换了这段代码:

<?PHP
add_filter('mce_external_plugins', 'myplugin_register_tinymce_javascript');

function myplugin_register_tinymce_javascript($plugin_array) {
   $plugin_array['myplugin'] = plugins_url('/fullpage_plugin/plugin.min.js',__file__);
   return $plugin_array;
}
?>

以下代码:

<?PHP
add_filter('mce_external_plugins', 'my_custom_plugins');

function my_custom_plugins () {
     $plugins = array('fullpage'); //Add any more plugins you want to load here
     $plugins_array = array();

     //Build the response - the key is the plugin name, value is the URL to the plugin JS
     foreach ($plugins as $plugin ) {
          $plugins_array[ $plugin ] = plugins_url('tinymce/', __FILE__) . $plugin . '/plugin.min.js';
     }
     return $plugins_array;
}
?>

并将plugin.min.js更改为相应的路径。

有效!