Advertisement
imath

Prevent comment bot spamming in WordPress.

Jun 1st, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2. /******* in functions.php of active theme ********/
  3.  
  4. /**
  5. * Proposition of Use of tellyworth suggestion to avoid bot spamming without modifying core
  6. * http://core.trac.wordpress.org/attachment/ticket/10975/wp-comment-nonce-refresh.patch
  7. */
  8.  
  9. add_action('pre_comment_on_post', 'amauri_check_hidden_field');
  10.  
  11. function amauri_check_hidden_field() {
  12.     $user = wp_get_current_user();
  13.     if ( !isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], "comment_form_{$comment_post_ID}") ) {
  14.         do_action('comment_nonce_failed', $comment_post_ID);
  15.         wp_die( __('Sorry, automated comments are not accepted.') );
  16.     }
  17. }
  18.  
  19. add_action('comment_form', 'amauri_add_hidden_field');
  20.  
  21. function amauri_add_hidden_field() {
  22.     wp_nonce_field("comment_form_{$post_id}", '_wpnonce', false);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement