How to make comment text field un-required?

My requirements are bit different I was able to hide email and website field with filter but what I want to know is there a way to make comment text un-required when I am giving comment without comment text area filled its giving me error that comment is required please guide me how i can make comment text unrequired.

       add_action('pre_comment_on_post', 'dump_comment');
       function dump_comment($post_id, $author=null,     $email=null) {
       $comcnt = $cmntcount = comments_number( '#0', '#1', '#%' );
       $comment = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
       if (!$comment) {
       $_POST['comment'] = 'Design' . $comcnt;

        }
        }

Updated and working code.

Read More
      add_action('pre_comment_on_post', 'dump_comment');
      function dump_comment($post_id, $author=null, $email=null) {
       $comment = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
       if (!$comment) {
       $_POST['comment'] = 'Design #' . get_comments_number();

       }
        }

making the comment unique everytime. by adding the value of comment count.

Related posts

3 comments

  1. 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
        }
    }
    
  2. function rei_preprocess_comment($comment_data) {
        if ($comment_data['comment_content'] == '%dummy-text%') {
            $comment_data['comment_content'] = ''; // replace dummy text.
        }
        return $comment_data;
    }
    add_filter('preprocess_comment', 'rei_preprocess_comment');
    function rei_wp_footer() {
        ?>
        <script>
        jQuery(function($){
            var comment = $('textarea#comment');
            comment.removeAttr('required'); // remove required attribute of textarea.
            $('#commentform').on('submit',function(){
                if (comment.val() == '') {
                    comment.css('text-indent','-999px').val('%dummy-text%'); // change to dummy text.
                }
            });
        });
        </script>
        <?php
    }
    add_action( 'wp_footer', 'rei_wp_footer' );
    
  3. This function allows the user to submit a comment without any text in the textarea. Then all you need to do is hide the comment textarea with some display:none; css.

    function rei_preprocess_comment($comment_data) {
        if ($comment_data['comment_content'] == '%dummy-text%') {
            $comment_data['comment_content'] = ''; // replace dummy text.
        }
        return $comment_data;
    }
    add_filter('preprocess_comment', 'rei_preprocess_comment');
    function rei_wp_footer() {
        ?>
        <script>
        jQuery(function($){
            var comment = $('textarea#comment');
            comment.removeAttr('required'); // remove required attribute of textarea.
            $('#commentform').on('submit',function(){
                if (comment.val() == '') {
                    comment.css('text-indent','-999px').val('%dummy-text%'); // change to dummy text.
                }
            });
        });
        </script>
        <?php
    }
    add_action( 'wp_footer', 'rei_wp_footer' );
    

Comments are closed.