teeny_mce_buttons
云策文档标注
概述
teeny_mce_buttons 是一个 WordPress 过滤器,用于自定义 TinyMCE 编辑器在“代码”标签页中的工具栏按钮列表。开发者可以通过此过滤器修改按钮数组,以控制显示哪些按钮。
关键要点
- 过滤器名称:teeny_mce_buttons
- 参数:$mce_buttons(数组,表示按钮列表)和 $editor_id(字符串,编辑器唯一标识符,如 'content')
- 用途:允许开发者过滤和修改 teenyMCE 工具栏按钮,常用于简化或定制编辑器界面
- 版本历史:从 WordPress 2.7.0 引入,3.3.0 版本添加了 $editor_id 参数
代码示例
/**
* 自定义 teenyMCE 按钮,仅保留格式选择、粗体和斜体按钮。
*
* @param $buttons 按钮数组
* @param $editor_id 编辑器标识符
* @return array 修改后的按钮列表
*/
function prefix_custom_teeny_mce_buttons( $buttons, $editor_id ) {
$buttons = array( 'formatselect', 'bold', 'italic' );
return $buttons;
}
add_filter( 'teeny_mce_buttons', 'prefix_custom_teeny_mce_buttons', 10, 2 );
原文内容
Filters the list of teenyMCE buttons (Code tab).
Parameters
$mce_buttonsarray-
An array of teenyMCE buttons.
$editor_idstring-
Unique editor identifier, e.g.
'content'.
Source
$mce_buttons = apply_filters( 'teeny_mce_buttons', $mce_buttons, $editor_id );
Skip to note 2 content
Mahdi Yazdani
/** * The following snippet shows you how to limit the toolbar buttons to the * text format dropdown, and the bold and italic buttons. * * @access public * @param $buttons An array of teenyMCE buttons. * @param $editor_id Unique editor identifier, e.g. 'content'. * @return array List of teenyMCE buttons */ function prefix_custom_teeny_mce_buttons( $buttons, $editor_id ) { $buttons = array( 'formatselect', 'bold', 'italic' ); return $buttons; } add_filter( 'teeny_mce_buttons', 'prefix_custom_teeny_mce_buttons', 10, 2 );