Cancel comment filter?

Is it possible to cancel comment submission if certain creteria are met?

I want to limit the number of characters in a comment. Where do I test the length and cancel the comment if it’s over a given length?

Read More

Would the pre_comment_approved filter do this? And does anyone have some sample code for how to use pre_comment_approved ?

Thanks

Related posts

Leave a Reply

1 comment

  1. You are certainly on the right track. You can create a plugin (create a directory in “wp-content/plugins” and create a php file with the same name as the folder) with the following code:

    function wpse_33944_filter_handler( $approved , $commentdata ){
        if(strlen($commentdata[comment_content]) > 5) {
            return false;
        }
        return true;
    }
    add_filter( 'pre_comment_approved' , 'wpse_33944_filter_handler' , '99', 2 );