Skip to content

Instantly share code, notes, and snippets.

@toddmotto
Created November 21, 2012 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddmotto/4128406 to your computer and use it in GitHub Desktop.
Save toddmotto/4128406 to your computer and use it in GitHub Desktop.
add_filter('pre_comment_content', 'encode_code_in_comment');
function 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>" . esc_html( $matches[1] ) . "</code>";'
),
$source);
if ($encoded)
return $encoded;
else
return $source;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment