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).

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

3 Answers
3

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>';
}

Leave a Reply

Your email address will not be published. Required fields are marked *