How to *disable* the post content editor

Any good ideas on how to disable the post content editor? I don’t want to hide it, remove it, or remove the page.

The goal is to allow users with few permissions to view the edit screen so they can read the content, but not be able to make changes to the content. (I also need to figure out how to disable other elements on the page, but one step at a time).

Read More

I’ve done this with Javascript already by just targeting the textarea and added disabled, but looking for a less flimsy method.

Background for why I need this: https://github.com/post-forking/post-forking/pull/105

Related posts

3 comments

  1. I think the best way is remove it and then print the content out of any textarea, but just as html:

    add_action('load-post.php', 'read_only_content');
    
    function read_only_content() {
      if ( ! current_user_can('manage_options') ) { // change the cap with the wanted one
        $scr = get_current_screen();
        remove_post_type_support( $scr->post_type, 'editor' );
        add_action('edit_form_after_editor', 'print_the_content');
      }
    }
    
    function print_the_content( $post ) {
      echo '<h2>' . __('Post Content:') . '</h2>';
      echo '<div id="content" style="width=99%;margin:15px 0;padding:1%;border:1px solid #aaa">'; 
      echo apply_filters('the_content', $post->post_content);
      echo '</div>';
    }
    
  2. Maybe I am blond but above could be solved by just changing some role options?

    I am aware that my answer is not pointing to question above but followed intentions you point yourself as mentioned in github. (questions/wishes are not equeal at all, here in question made above you want to disable edit and so also publish options and in github you want to disable publishing option but still able to edit!? (allowing Billy to make corrections)

    Billy seems in a way some kind of editor (is not explained in github who the author is, but assuming he isn’t).

    You could make changes in roles (I would make a new role with restrictions, enough for him to make ccorrections in the text) and restrict some options. (disable publish_posts/publish_pages)

    Now he is able to make the text corrections and only able to click “submit for Review”. You as his Boss (assume you are the editor) are able to check and when needed make corrections and are able to publish when needed.

    If my assuments are correct then this would be a fast and reliable way to achieve what you want. If I am totally incorrect, please tell and I will delete this answer.

  3. you can remove the <?php edit_post_link(); ?> code in your single.php or post php to remove edit option..,i not use custom permission method and put that code inside if/else code where you checking that.,

Comments are closed.