Last active
August 29, 2015 14:10
-
-
Save michaelbonner/867ae7ddced3389dfe87 to your computer and use it in GitHub Desktop.
Stop WordPress Comment Spam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check to see if the hidden input exists in submission | |
function preprocess_new_comment($commentdata) { | |
if(!isset($_POST['is_legit'])) { | |
die(); | |
} | |
return $commentdata; | |
} | |
add_action('preprocess_comment', 'preprocess_new_comment'); | |
// add hidden field to form | |
function add_field_to_comment_form() { | |
?> | |
<script> | |
jQuery( document ).ready( function($) { | |
$('#commentform').prepend('<input type="hidden" name="is_legit" value="1" />'); | |
}); | |
</script> | |
<? | |
} | |
add_action( 'wp_footer', 'add_field_to_comment_form' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment