Wordpress: Escape HTML Entities in Comments


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * Escape HTML Entities in Comments
  3.  * tell your commentators to wrap their code snippets in <code> tags
  4.  * http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/
  5.  *
  6.  **/
  7. function myfunction_encode_code_in_comment($source) {
  8. $encoded = preg_replace_callback('/<code>(.*?)<\/code>/ims',
  9. create_function('$matches', '$matches[1] = preg_replace(array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "", $matches[1]);
  10. return "<code>" . htmlentities($matches[1]) . "</"."code>";'), $source);
  11. if ($encoded)
  12. return $encoded;
  13. else
  14. return $source;
  15. }
  16. add_filter('pre_comment_content', 'myfunction_encode_code_in_comment');

URL: http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.