Remove specific buttons from wp_editor()

If you are using the settings API, you can use exactly the same code for calling wp_editor as you would anywhere else

I’ve test the code below, it adds a setting section to the reading section, and then adds a field to the section containing a WYSIWYG editor with buttons limited to link, img and 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);
 }

Leave a Comment