How to allow duplicate comments AND without comment text

I've searched hard but I've been nowhere near close to finding the answer to this...

I have a comment meta box that gives the commentor two tick boxes. The tick box is the only input into their comment, therefore there is lots of duplicate comments. At the same time there is no content in the comment.

So I need two things... firstly allow a comment with no text input needed, and secondly, allow duplicate comments.

Topic duplicates comments Wordpress

Category Web


WordPress will not allow you, using its default comment process, to insert empty comments into the database. This is enforced by wp_handle_comment_submission() with the following unconditional code:

if ( '' == $comment_content ) {
    return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 200 );
}

If you insist on using comments, you will need to supply some non-empty value for $comment_content, which is most simply accomplished by inserting some whitespace content into the comment field itself.

As for duplicates, since WordPress 4.4.0 you can allow duplicate comments by using the duplicate_comment_id filter hook. As per the docs:

Filters the ID, if any, of the duplicate comment found when creating a new comment.

Return an empty value from this filter to allow what WP considers a duplicate comment.

For example, use the following code to unconditionally allow duplicate comments:

add_filter('duplicate_comment_id', '__return_false');

Hope this helps. :)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.