Return to Snippet

Revision: 47343
at June 6, 2011 01:06 by alp


Initial Code
/**
 * Escape HTML Entities in Comments
 * tell your commentators to wrap their code snippets in <code> tags
 * http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/
 *
 **/
function myfunction_encode_code_in_comment($source) {
	$encoded = preg_replace_callback('/<code>(.*?)<\/code>/ims',
	create_function('$matches', '$matches[1] = preg_replace(array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "", $matches[1]); 
	return "<code>" . htmlentities($matches[1]) . "</"."code>";'), $source);
	if ($encoded)
		return $encoded;
	else
		return $source;
}
add_filter('pre_comment_content', 'myfunction_encode_code_in_comment');

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

Initial Description

                                

Initial Title
Wordpress: Escape HTML Entities in Comments

Initial Tags
wordpress, code

Initial Language
PHP