Sometimes, the visitors posted their code in the comment section. That is an awesome way to share and communicate. However, in some cases, partial of the code inside pre/code section is missing. This unexpected feature bothered me for a long time. Today, I fixed it with a modification of a plugin.
Issue: Some code inside pre/code section of comment will be missing, if it is posted by guest. For example, if the guest input the following comment:
<pre> <>& </pre>
It will be modified to:
<pre> & </pre>
Cause: WordPress will automatically sterilize the original input. Because < and > are two special html tokens, some of them and probably the content inside the pairs will be removed/modified. As a result, some code is missing.
Solution: escape these three special HTML tokens at the very beginning of the comment process.
add_filter( 'content_save_pre', 'filterCode', 9 );
add_filter( 'excerpt_save_pre', 'filterCode', 9 );
add_filter( 'preprocess_comment', 'filterCode', 0 );
Finally, active the plugin.