2017-02-10 14 views
0

TinyMCEにボタンを追加するためにwordpressにプラグインを作成しました。 https://www.gavick.com/blog/wordpress-tinymce-custom-buttons#tc-section-1TinyMCEワードプレス、カスタムボタンが表示されません

PHPファイル

< ? php 
    /* 
    Plugin Name: TinyMCE Custom Buttons 
    Plugin URI: 
    Description: 
    Version: 
    Author: 
    Author URI: 
    License: 
    License URI: 
    */ 

    //Hook the button on init, so after loading wordpress 
    add_action('init', 'add_button1234'); 

    //add filters within th function which loads after loading wordpress 
    function add_button1234() { 
     // add new buttons 
     add_filter('mce_buttons', 'myplugin_register_buttons1234'); 
     // Load the TinyMCE plugin 
     add_filter('mce_external_plugins', 'register_1234'); 
    } 


    //Add the newly created button to ithe $buttons array 
    function register_1234($buttons) { 
     array_push($buttons, 'separator', 'button1234'); 
     return $buttons; 
    } 

    //create the button 
    function myplugin_register_tinymce_javascript1234($plugin_array) { 
     $plugin_array['button1234'] = plugins_url('plugin.js', __FILE__); 
     return $plugin_array; 
    } 
?> 

また

(function() { 
    tinymce.PluginManager.add('button1234', function(editor, url) { 
     editor.addButton('button1234', { 
      text: 'My test button', 
       icon : false, 
       onclick : function() { 
       editor.insertContent('Hello World!'); 
      } 
     }); 
    }); 
})(); 

が、私は正確に従ってjavascriptのファイル:私はここに非常に厳密に例を次のコードこれを下回る瞬間に持っていますコードをサイトから(JS URLを適合させるだけではうまくいきません)どうすれば間違っている可能性がありますか?

答えて

0

add_button1234()機能にフィルタmce_buttonsを追加するときに、適切な機能を呼び出さない可能性があります。

変更この行:

add_filter('mce_buttons', 'myplugin_register_buttons1234'); 

へ:

add_filter('mce_buttons', 'myplugin_register_tinymce_javascript1234'); 
+0

私はそれをしたとビジュアルTinyMCEの上のすべてのボタンが真っ白になった、ありがとうございます。 (これ以上のボタンはありません)これはどういう考えですか? – Nateno

+0

'$ plugin_array ['button1234'] = plugins_url( 'plugin.js'、__FILE __);'行にJavaScriptファイルのパスが正しく設定されていますか? – mbacon40

+0

"plugin.js"ファイルは.phpファイルと同じディレクトリにありますので、正しいと思います。 – Nateno

関連する問題