How to make comment text field un-required?

You can circumvent the check for empty comments easily by adding the uploaded image as HTML to the comment text:

add_action( 'pre_comment_on_post', 'allow_empty_comment_text' );

function allow_empty_comment_text( $text="" )
{
    if ( ! isset ( $_POST['comment'] ) or '' === trim( $_POST['comment'] ) )
    {
        $img = '/* Process uploaded image here, create an <img> tag. */'    
        $_POST['comment'] = '<img>'; // use a real img tag here
    }
}

Leave a Comment