3

I've got a great Comment Form and Threaded Comments setup by using the native WordPress functions: comment_form and wp_list_comments.

However, I'm trying to also create a custom Contest Comment template for certain posts. I call comments_template('/contest-comments.php', true); conditionally based on whether a certain custom field exists or not. It works great.

I'm trying to make it look along the lines of http://2010.sf.wordcamp.org/attendees/

I only want to show the person's name wrapped in a link and their avatar. Therefore, I want my comment form to only show the Name, Email, and URL fields. The text area should be hidden.

For the Comment Form, I am passing an empty value for the comment_field key in the $args array I'm passing into comment_form.

This makes the comment form look okay, but when someone submits a comment, they get a warning from WordPress saying that their message was blank.

Any solutions on how to solve this? Thanks!

2 Answers 2

7

Short answer: It doesn't, but you can get around this:

add_filter('comment_form_field_comment', 'my_comment_form_field_comment');
function my_comment_form_field_comment($default){
  return false;
}

add_action('pre_comment_on_post', 'my_pre_comment_on_post');
function my_pre_comment_on_post($post_id){
  $some_random_value = rand(0, 384534);
  $_POST['comment'] = "Default comment. Some random value to avoid duplicate comment warning: {$some_random_value}";
}

If you want this only for certain pages, then you should create a custom page template, for eg "boo.php", and in the code I posted above, only add these filters if the current page template is boo (use $post->page_template to get the current page template when doing the check).

Related questions:

3
  • I intend to use this on a universal single.php file with a custom comment template. I'm a bit confused as to why I would need a custom page template. Dec 21, 2010 at 18:27
  • you don't, if you want that textarea disabled trough the entire site. Dec 21, 2010 at 18:50
  • 1
    I got it working, I just found another trick to solve the issue. I turned what would be normally the text area into a hidden field with a value that includes the time, article title, and post ID. That avoid the duplicate warning issue. Dec 22, 2010 at 6:27
0

Yes, it does, use the allow_empty_comment hook, see details here:

https://developer.wordpress.org/reference/hooks/allow_empty_comment/

Here is a sample:

// Enable empty comment.
add_filter( 'allow_empty_comment', '__return_true' );

You may also consider unchecking the checkbox in Settings > Discussion for:

Comment author must fill out name and email

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.