从wp_EDITOR()中删除特定按钮

时间:2013-09-16 作者:JMau

我知道也有类似的话题,有公认的答案,但我找不到我想要的。我只想保留基本按钮wp_editor(). 我在选项页中使用此选项,以使书写更加舒适。

问题是这个主题在这个特定的页面上添加了大量我不想要的快速标签。我怎样才能做到这一点。

到目前为止我已经调查过了wp-includes/wp-class-editor.php 但以下行不会删除不必要的按钮:

\'quicktags\' => array(\'buttons\' => \'link,ins,img,close\')
:/。

编辑:我试图修改类似主题中给出的函数:

function wpa_47010( $qtInit ) {
global $my_plugin_page;
    $screen = get_current_screen();
      if( $screen->id == $my_plugin_page ) 
          $qtInit[\'buttons\'] = \'link,img,close\';
return $qtInit;
}
add_filter(\'quicktags_settings\', \'wpa_47010\');
但它不起作用!

2 个回复
最合适的回答,由SO网友:Matt.C 整理而成

如果您使用的是设置API,则可以使用与其他任何地方完全相同的代码来调用wp\\U编辑器

我已经测试了下面的代码,它在阅读部分中添加了一个设置部分,然后在包含所见即所得编辑器的部分中添加了一个字段,该编辑器的按钮仅限于link、img和close

// Add a setting to the reading page
 function register_plugin_x_settings() {
    // Add a section to reading settings 
    add_settings_section(\'plugin_x_setting_section\',\'Plugin X (section caption)\',\'plugin_x_setting_section_callback\',\'reading\');

        // add setting field
    add_settings_field(\'plugin_x_setting_wysiwyg\', \'WYSIWYG Content\', \'plugin_x_setting_wysiwyg_callback\', \'reading\', \'plugin_x_setting_section\');
    register_setting(\'reading\',\'plugin_x_setting_wysiwyg\');
 }
 add_action(\'admin_init\', \'register_plugin_x_settings\');

 // function to render the section
 function plugin_x_setting_section_callback() {
    echo \'<p>Plugin X Settings</p>\';
 }

// function to render the setting
function plugin_x_setting_wysiwyg_callback() {
    // global editor id (not necesary, but we may need it elsewhere)
    global $myPluginEditorID;
    $myPluginEditorID = "myPluginEditorUniqueID";

    // settings to pass to wp_editor, disables the upload button, and sets minimal quicktags and turns off tinymce
    $settings = array(
        \'media_buttons\' => false,
        \'quicktags\'     => array("buttons"=>"link,img,close"),
        \'textarea_name\' => "input_{$myPluginEditorID}",
        \'tinymce\'       => false,
    );

    // output the wysiwyg editor
    wp_editor( "Content Here", $myPluginEditorID,$settings);
 }

SO网友:Matt.C

下面的代码对我很有用,它添加了一个选项页面,并向该页面添加了一个所见即所得框,其中只有3个快速标记:link、img和close,而没有其他标记。

注意,我打开了tinyMCE,并将设置数组(其中包含另一个用于quicktag设置的数组)传递给wp\\U编辑器。

通过传入textarea字段的唯一id,它只会影响插件选项页上的正确框

// add admin page
function my_admin_add_page() {
    global $my_admin_page;
    $my_admin_page = add_options_page(__(\'My Admin Page\', \'map\'), __(\'My Admin Page\', \'map\'), \'manage_options\', \'map\', \'my_admin_page\');
}
add_action(\'admin_menu\', \'my_admin_add_page\');

// render admin page
function my_admin_page() {
    // global editor id (not necesary, but we may need it elsewhere)
    global $myPluginEditorID;
    $myPluginEditorID = "myPluginEditorUniqueID";

    // settings to pass to wp_editor, disables the upload button, and sets minimal quicktags and turns off tinymce
    $settings = array(
        \'media_buttons\' => false,
        \'quicktags\'     => array("buttons"=>"link,img,close"),
        \'textarea_name\' => "input_{$myPluginEditorID}",
        \'tinymce\'       => false,
    );

    // output the wysiwyg editor
    wp_editor( "Content Here", $myPluginEditorID,$settings);
}

结束

相关推荐