Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration 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.

      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.

share|improve this question
    
It sounds like (based on a comment to @toscho's answer) that you have a lot of requirements that you have not specified in the question. For one, it sounds like you are trying to replace the text comment box with something else? Please edit the question to explain exactly what you are doing rather than just asking how to remove the comment box. –  s_ha_dum Jun 1 '13 at 17:15
    
I have already achieved all the things expect the removal of requirement of the Comment text area as toscho answered that if somebody going to re-comment with any thing it will be duplicated and hence making it not allowed. So right now I want a guide that how I can make Comment text are not required. –  Cid Ubaid Jun 1 '13 at 18:47
    
Yes, but your proposed solution to this last issue is problematic. Removing the comment text requirement is causing trouble. There is at least a chance of this being an XY problem. Explain what the goal is, not what you imagine the solution to be. There may be another way to do this. –  s_ha_dum Jun 1 '13 at 18:57
    
In case anyone want's this to work updating the code above. –  Cid Ubaid Jun 2 '13 at 11:55
    
If you have an answer for your question then please post it in the answer box and not as an edit to the question. –  s_ha_dum Jun 2 '13 at 13:47

1 Answer 1

up vote 2 down vote accepted

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
}
}
share|improve this answer
    
Yes that is the main problem -- actually to be frank here I am developing my own theme for designer's where they can come and show their work - through comments I have work a lot hard on comment thinking it would be easy to unchecked the text are out of requirement and now I am stuck I am letting designer's submit images through comment - but I am all stuck because the comment field is required and its just messing my design if somebody comment any thing and I don't want designer to ristrict for one image only - I want a way to make it not required . –  Cid Ubaid Jun 1 '13 at 16:11
    
@CidUbaid Then use the image markup as comment content. That would solve the other problems too. –  toscho Jun 1 '13 at 17:21
    
Can you please explain what does it means ? –  Cid Ubaid Jun 1 '13 at 18:42
    
@CidUbaid See my update. –  toscho Jun 1 '13 at 18:47
    
That's great Toscho - but just one more question ? it will automatically write the tag of the image as a comment ? and on your suggestion that was absolutely great I was thinking why not make it something like design no#1, design no#2 design no#3 and so on depending on the comment counts ? lets say if we have 3 comment's and the 4rth one just uploaded the image it will write design no#4 as a comment ? –  Cid Ubaid Jun 1 '13 at 18:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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