Skip to content

Instantly share code, notes, and snippets.

@sumhat
Created December 27, 2014 21:41
Show Gist options
  • Save sumhat/cc4ef49f70b664c24762 to your computer and use it in GitHub Desktop.
Save sumhat/cc4ef49f70b664c24762 to your computer and use it in GitHub Desktop.
<pre class="lang:php">
function leonax_anti_spam_form($fields){
global $leonax_magic_lower, $leonax_magic_upper;
$leonax_magic = mt_rand($leonax_magic_lower, $leonax_magic_upper);
$fields['leonax_magic'] = <<<EOT
<input type="hidden" id="leonax-magic" name="leonax-magic" value="0">
<script type="text/javascript">
jQuery(function() {
jQuery("#comment").on("keyup", function() {
jQuery("#leonax-magic").val("$leonax_magic");
});
})
</script>
EOT;
return $fields;
}
add_filter('comment_form_default_fields', 'leonax_anti_spam_form');
</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment