WordPress duplicate comment detection

Does anyone know how to disable duplicate comment detection in WordPress (2.9.2)? I’m looking for a way to do this programatically without editing core files. We’re adding comments via XMLRPC and the duplicate detection in wp-includes/comment.php (line 494) is causing issues during testing.

Thanks!

Related posts

Leave a Reply

4 comments

  1. Actually, you don’t need to edit ANY core files to do this. Just put these one filter and two tiny functions in your theme’s functions.php file and duplicate comments will no longer be rejected.

    add_filter( 'wp_die_handler', 'my_wp_die_handler_function', 9 ); //9 means you can unhook the default before it fires
    
    function my_wp_die_handler_function($function) {
        return 'my_skip_dupes_function'; //use our "die" handler instead (where we won't die)
    }
    
    //check to make sure we're only filtering out die requests for the "Duplicate" error we care about
    function my_skip_dupes_function( $message, $title, $args ) {
        if (strpos( $message, 'Duplicate comment detected' ) === 0 ) { //make sure we only prevent death on the $dupe check
            remove_filter( 'wp_die_handler', '_default_wp_die_handler' ); //don't die
        }
        return; //nothing will happen
    }
    
  2. Currently, there are no hooks available to do this without editing core files.

    The best way would be to comment out the duplicate check from wp-includes/comment.php

  3.     $dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_approved != 'trash' AND ( comment_author = '$comment_author' ";
    if ( $comment_author_email )
        $dupe .= "OR comment_author_email = '$comment_author_email' ";
    $dupe .= ") AND comment_content = '$comment_content' LIMIT 1";
    
  4. I had the same issue when replying in the backend on comments.

    But just replying with the same comment on the frontend worked fine without changing anything.

    Hope this might help someone.