TinyMCE wordpress,自定义按钮不显示

问题描述 投票:0回答:1

我在 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 url,它不起作用。)我可能做错了什么?

php wordpress button tinymce
1个回答
0
投票

看起来您在

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

更改此行:

add_filter( 'mce_buttons', 'myplugin_register_buttons1234' );

致:

add_filter( 'mce_buttons', 'myplugin_register_tinymce_javascript1234' );
© www.soinside.com 2019 - 2024. All rights reserved.