Custom comment type based on thread level

I don’t know why somebody downvoted this question. This is a GREAT question.

Yeah, that’s totally possible. What you would want to do is use comment_meta to store the titles. You could add the new field into the form using the 'comment_form_top' action. It runs before name, email, and url, and still runs if the user is logged in, so you’d get the field for every user. Just echo the html directly.

Then you’d want to hook into 'pre_comment_on_post' to check if there’s a title. Use wp_die() to exit execution if there’s nothing there.

You should hook into the 'comment_post' action to save the title. That hook passes two arguments: the comment_id and the comment’s approval status. The only one you should need is the comment ID. Sanitize the input with esc_attr() and add the comment_meta.

The last thing you might consider is adding some javascript that would automatically set the title and hide the field for comment replies. The comment reply links all have a class of 'comment-reply-link', so it wouldn’t be too difficult to hook in with jQuery.

Hope that helps you get on the right track!

Leave a Comment