0

So basically, I am using the Wordpress editor on my site and I do not want my users posting ANY HTML in it at all since it can cause some problems.

My Wordpress Editor is currently like this:

<?php wp_editor( get_the_content() , 'post_content'); ?>

In simple terms, I would basically like it to just look like a simple HTML textarea, and strip all HTML tags (like what the PHP function strip_tags does. Although, I cannot get this PHP functionality working with a simple textarea... Not to sure why, just a coding problem with my theme.

So yes, is something like this possible?

1

Remove post type support for the editor:

add_action(
  'init',
  function() {
    remove_post_type_support( 'post', 'editor');
  }
);

Now add a new meta box containing only a textarea

// print a new meta box
function generic_cb($post) {
  $content = (!empty($post->post_content)) ? $post->post_content : '';
  echo '<textarea name="content">'.$content.'</textarea>';
}

function add_before_editor($post) {
  global $post;
  add_meta_box(
    'generic_box', // id, used as the html id att
    __( 'Text Only Content' ), // meta box title
    'generic_cb', // callback function, spits out the content
    'post', // post type or page. This adds to posts only
    'pre_editor', // context, where on the screen
    'high' // priority, where should this go in the context
  );
  do_meta_boxes('post', 'pre_editor', $post);
}
add_action('edit_form_after_title','add_before_editor');

And save

// strip your data on save
function strip_post_content_markup($data) {
  if (!empty($data['post_content'])) {
    $data['post_content'] = strip_tags($data['post_content']);
  }
  return $data;
}
add_filter('wp_insert_post_data','strip_post_content_markup',1);

That is the cleanest solution I can come up with.

| improve this answer | |
  • Seems like a great solution, but I am extremely confused on how to get this working. Could you break it down a little for me by any chance? Am I basically removing my piece of code that I posted with all of your code? – Fizzix Nov 4 '13 at 4:52
  • If you paste those blocks of code into a plugin or MU-PLugin file, even your themes's functions.php, it should work. I left formatting the textarea up to you. – s_ha_dum Nov 4 '13 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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