【问题标题】:Not show hr through teeny_mce_buttons filter不通过 teeny_mce_buttons 过滤器显示小时
【发布时间】:2017-11-17 10:11:15
【问题描述】:

我正在为我的 wp 主题构建自定义 tinymce 栏按钮,使用 wp_editor 和 teeny,但我遇到了问题。当我添加 hr 和 charmap 时,这些按钮不会出现在 tinymce 栏中。

这是 wp_editor 配置:

 $settings = array( 
                'textarea_name' => 'xor_options[' . $editor . ']',
                'quicktags'     => array( 'buttons' => 'strong,em,del,ul,ol,li,close' ),
                'media_buttons' => true,
                'wpautop'   => false,
                'textarea_rows' => 5,
                'editor_height' => 200,
                'teeny' => true,
                'tinymce' => true
        );
 wp_editor( $xor_output, $xor_editor_id, $settings );

现在我正在为小按钮使用过滤器。

add_filter( 'teeny_mce_buttons', 'xor_editor_buttons', 10, 2 );
function xor_editor_buttons( $buttons, $editor_id ) {

    if( $editor_id != 'footer-editor' ) return $buttons;

    $buttons = array( 
        'undo',
        'redo',
        'formatselect',
        'bold', 
        'italic', 
        'underline', 
        'strikethrough',
        'blockquote',
        'bullist',
        'numlist',
        'outdent',
        'indent',
        'alignleft', 
        'alignright',
        'aligncenter', 
        'alignjustify',
        'link',
        'unlink',
        'hr', // not appears!
        'charmap', // not appears!
        'removeformat',
        'fullscreen'
        );

    return $buttons;
}

我的代码中的错误在哪里,或者这是一个小错误?我正在使用 Wordpress 4.9。谢谢!


已解决

我设置了 false teeny。然后我将 tinymce 设置为数组:

'tinymce'       => array(
            'toolbar1'      => $b,
            'toolbar2'      => '',
            'toolbar3'      => '',
        )

$b 是我需要的所有按钮(包括 hr 和charmap)。看: Wordpress Developers

【问题讨论】:

    标签: wordpress tinymce


    【解决方案1】:

    在加载工具栏按钮之前,您需要加载插件:

    https://www.tinymce.com/docs/plugins/hr/ https://www.tinymce.com/docs/plugins/charmap/

    您首先需要查看嵌入在您的 WP 版本中的 TinyMCE 是否包含这些插件(它们在标准的 WordPress 设置中)。然后,您需要将这些插件添加到加载的插件列表中。加载后,将按钮添加到工具栏即可。

    我对@9​​87654323@ 一无所知,但(例如)这是 TinyMCE Advanced 如何通过 WordPress 挂钩加载额外插件的方式:

     add_filter( 'tiny_mce_plugins', array( $this, 'tiny_mce_plugins' ), 999 );  
    

    (数组是插件文件夹名称的列表)

    【讨论】:

    • 感谢您的回答。我不知道你的解决方案是否有效。我用其他方式解决了。请参阅上面我更新的问题!
    猜你喜欢
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    • 1970-01-01
    相关资源
    最近更新 更多