Disable text tab on WordPress text-editor

All we need is an easy explanation of the problem, so here it is.

I’m looking for a way to disable text tab on wordpress text-edito (red square on the pic) for all my users roles except ADMINISTRATOR because i don’t want them to have the possibility to add javascript code on the pages. I also looking for a way to add justify icon to the text-editor (like you see on the pic in red too).

now i found a way to hide text tab for all users with the code bellow

    function my_editor_settings($settings) {
    $settings['quicktags'] = false;
    return $settings;
    }

    add_filter('wp_editor_settings', 'my_editor_settings');

How can add an exception for ADMINISTRATOR role?

enter image description here

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

For disabling the text tab for all users except administrators, you can add the following:

function my_editor_settings($settings) {
    if ( ! current_user_can('administrator') ) {
        $settings['quicktags'] = false;
        return $settings;
    } else {
        $settings['quicktags'] = true;
        return $settings;
    }
}

add_filter('wp_editor_settings', 'my_editor_settings');

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply