2

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

5

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

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.

1
  • Great thoughts Charles. Let me clarify a few things. Billy needs to be able to edit UNTIL the post is approved. Once its approved Billy can't do anything except for publish. And that's key -- he has to have the edit_posts cap to see the screen and the publish_posts cap so we can publish, but without being able to edit. Commented Nov 27, 2013 at 21:17
-1

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

3
  • I think you misunderstood the question. In the Admin on the Post Edit screen he wants to disable the post editor. Commented Nov 27, 2013 at 12:19
  • Yes, what @Charles said: my question is concerning the administrative view of editing a post. Commented Nov 27, 2013 at 15:14
  • sorry i got the question wrong.... Commented Nov 28, 2013 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.