Wordpress duplicate comment detection
Asked Answered
I

5

5

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!

Ilion answered 31/5, 2010 at 10:57 Comment(0)
B
3

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

Bocanegra answered 31/5, 2010 at 11:1 Comment(1)
This means that if the same author writes more than one comment on the same post, it is considered a duplicate. Which is just plain wrong! But thanks for your answer.Ilion
R
12

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
}
Ropeway answered 21/7, 2012 at 19:54 Comment(2)
Warning: This removes some important checks. For example people are able to comment anonymous although not allowed via settings. You can test this by loading a post, removing your cookies and then trying to send the comment.Seaway
For a more elegant solution see: strangerstudios.com/blog/2010/10/…Seaway
B
3

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

Bocanegra answered 31/5, 2010 at 11:1 Comment(1)
This means that if the same author writes more than one comment on the same post, it is considered a duplicate. Which is just plain wrong! But thanks for your answer.Ilion
I
0
    $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";
Ilion answered 2/6, 2010 at 13:32 Comment(0)
V
0

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.

Viewpoint answered 17/8, 2012 at 8:20 Comment(0)
M
0
// functions.php
add_filter( 'duplicate_comment_id', function( $dupe_id, $commentdata ) {
return '';
}, 10, 2 );
Macaulay answered 6/9, 2024 at 7:19 Comment(1)
Thank you for your interest in contributing to the Stack Overflow community. This question already has a few answers—including one that has been validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?Gyrus

© 2022 - 2025 — McMap. All rights reserved.