Change WordPress user roles and capabilities Forums How to or FAQ How to disable the Text Editor? – just Visuell Editor should be displayed

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2704
    kstockl
    Participant

    I´m on the way to building a News Website where Authors are able to write their own Posts/Articles.
    I want to disable the Text Editor (HTML Editor Button/Tab) for this Authors. They should just be able to see the Visuell Editor when the writing a new Post/Article.

    a) Can this be done by settings inside the User Role Editor Pro?

    b1) If not – how I am able to disable the Text Editor for Users per Role? And is planned to integrate a function where this is possible in the future?

    b2) Are there any Plugins which are able to diable this function or how can this be realized?

    Thanks for your answer
    Wit best Regards, Karl Stöckl

    #2708
    Vladimir
    Keymaster

    Hi Karl,

    Add this code to your active theme functions.php file or setup it as must use plugin:

    
    function my_editor_settings($settings) {
      if (!current_user_can('administrator')) {
        $settings['quicktags'] = false;
      }
      
      return $settings;
    }
    
    add_filter('wp_editor_settings', 'my_editor_settings');
    add_filter('wp_default_editor', create_function('', 'return "tinymce";'));
    
    #2709
    kstockl
    Participant

    Good Morning Vladimir,

    thank´s a lot of this advice 🙂

    So just a question – if I include this code snippet into my Theme functions.php it works perfect. But can you advice me how to integrate it as a Must USE plugin? I tried to do this but it does not work. What did I do?

    1. I created a folder in /wp-content with this structure /wp-content/mu-plugins
    2. I pasted your code-snippet into my Text Editor and saved this file with name: editor.php
    3. Uploaded this file into the new created directory: /wp-content/mu-plugins

    But when I tried this it wasn´t working. The snippet was printed as text line to the head of my Website. It seems that I just made something wrong.

    By the way I didn´t know about the must use Plugin till now. So ecery day I learn new secrets 😀

    Thank´s for your reply,

    With best Regard, Karl

    #2710
    Vladimir
    Keymaster

    You made all correctly except one thing: add as a 1st separate line to the file editor.php the tag

    
    <?php
    

    It will show to PHP interpretator where a PHP code starts.

    #2711
    Vladimir
    Keymaster

    If you wish to have more control it’s possible to integrate this code snippet with User Role Editor as the additional options for role:

    
    add_filter('ure_role_additional_options', 'add_visual_editor_only_option', 10, 1);
    function add_visual_editor_only_option() {
        $item = URE_Role_Additional_Options::create_item('visual_editor_only', esc_html__('Visual Editor Only', 'user-role-editor'), 'admin_init', 'ure_remove_text_editor');
        $items[$item->id] = $item;
        
        return $items;
    }
    
    function ure_remove_text_editor() {
      add_filter('wp_editor_settings', 'ure_editor_settings');
      add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );
    }
    
    function ure_editor_settings($settings) {
      if (!current_user_can('administrator')) {
        $settings['quicktags'] = false;
      }
      
      return $settings;
    }
    
    #2712
    kstockl
    Participant

    I tried this meanwhile but with one difference:

    <?php
    function my_editor_settings($settings) {
      if (!current_user_can('administrator')) {
        $settings['quicktags'] = false;
      }
      
      return $settings;
    }
    
    add_filter('wp_editor_settings', 'my_editor_settings');
    add_filter('wp_default_editor', create_function('', 'return "tinymce";'));
    ?>

    Here I got the 500 Error Message

    So I thought just to put this code snippet without the <?php ?>.

    My mistake was at the last line. Here I added ?>

    Thank you so much for your time and your support. Now with your advice the Editor is doing the job as I want.

    With best Regards from Austria,
    Karl

    #2714
    kstockl
    Participant

    Ah, I see… if I want take control for different Roles I have just to paste the Code in the Theme functions.php. Within this I´m able to to select different User Roles to be able to have the HTML Editor for advanced Article crating while normal Users are only able to use the Visual Editor.
    Great Advice 🙂

    Vladimir, may I suggest to you to maybe include this Feature function in one of your next Plugins Update? So that this special Editor Functions could enabled/disabled by default within User Roles Editor Plugin without the need of edit the Theme Functions.php?

    1.) So it would not be effected when Theme updates overwrite the changed settings.
    2.) It would be in my opinion a great feature addon too to control which of the Users are able to have full control of the HTML Editor. Some of the Users couldn´t break any Site anymore with wrong HTML Codes.
    3.) Admins would have less headache 😉

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.