Thursday 3 October 2013

How To Disable HTML In WordPress Comments

Important: All scripts hosted on widcraft.googlecode.com don't work anymore because Google has blocked that SVN repository.


I really hate spammers. They make me sick with their spam comments with all the bold text and hyperlinks. I know that I'm not the only one with this crappy problem, since spammers are everywhere these days. Some of them should write a book about "The life of a Spammer."

You can easily disable HTML in WordPress Comments.So if someone uses the strong code, it will not bold the text etc. It's really important for a WordPresser to disable HTML comments to prevent spammers from commenting with HTML formatted comments.

Just add following code in your functions.php file:

// This will occur when the comment is posted
function plc_comment_post( $incoming_comment ) {

// convert everything in a comment to display literally
$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);

// the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
$incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );

return( $incoming_comment );
}

// This will occur before a comment is displayed
function plc_comment_display( $comment_to_display ) {

// Put the single quotes back in
$comment_to_display = str_replace( ''', "'", $comment_to_display );

return $comment_to_display;


That's IT!
Important: Check our new website TricksPanda.com for WordPress tutorials, plugins and more.
 
Powered by Blogger.