I have a comment form that has name, email, brief, detailed and rating fields.

The name, email, brief and rating need to be required, but the latter two are custom fields and I can only make them required through Javascript, but want to add proper WordPress/PHP validation to those fields.

The detailed field is actually the comment_field which is currently required, but I want to removed the required for this field, but I don't want to do it via the WordPress settings as I still want name and email to be required.

2 Answers 2


Here is a related question that should answer yours. Basicly you want to use the pre_comment_on_post hook

    function custom_validate_comment() {
    //validate for brief and rating
if( empty( $_POST['brief']) || empty( $_POST['rating'])  )
        wp_die( __('Error: you must fill in both the rating and the brief') );
//make comment not required
if(empy($_POST['comment']){$_POST['comment'] == "empty_comment";}

add_action('pre_comment_on_post', 'custom_validate_comment');

function custom_change_comment( $commentdata ) {
    if( $commentdata['comment'] == 'empty_comment' )
        $commentdata['comment'] = '';
    return $commentdata;

add_filter('preprocess_comment', 'custom_change_comment');

That should at least get you on the right track

  • Awesome, that worked perfectly. Thanks for the help!
    – WolfieZero
    Commented Oct 18, 2011 at 9:42

For anyone who ends up here, the current way to do this is the allow_empty_comment filter

add_filter( 'allow_empty_comment', '__return_true' );


Your Answer

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

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