TinyMCE wordpress,自定义按钮不显示

时间:2017-02-10 15:15:15

标签: wordpress button tinymce

我在wordpress中创建了一个插件,为TinyMCE添加了一个按钮。我现在有下面的代码非常严格地遵循这里的例子: https://www.gavick.com/blog/wordpress-tinymce-custom-buttons#tc-section-1

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

javascript文件

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

此外,当我完全遵循网站上的代码时(仅调整JS网址,它不起作用。)我可能做错了什么?

1 个答案:

答案 0 :(得分:0)

mce_buttons函数中添加过滤器add_button1234()时,您似乎可能没有调用正确的函数。

更改此行:

add_filter( 'mce_buttons', 'myplugin_register_buttons1234' );

要:

add_filter( 'mce_buttons', 'myplugin_register_tinymce_javascript1234' );