Skip to:
Content
Pages
Categories
Search
Top
Bottom

Allow empty replies


  • bhkh
    Participant

    @bhkh

    I’m using an attachment plugin in bbPress. When someone uploads an attachment to a reply but does not put any text in the reply box (which is totally fine for this forum) and then clicks “Submit”, this is what happens:

    – the reply does not post
    – no error message is given
    – the form resets

    I’d like it if either

    – the reply posted with only the attachment
    – or there was an error message
    – or the form didn’t reset (i.e. clicking the button did nothing)

    As it is, it’s very confusing because there is no indication of failure. Someone would have to look for their reply to make sure it submitted. That’s not reliable.

    Thanks for any help!

Viewing 3 replies - 1 through 3 (of 3 total)

  • Robin W
    Moderator

    @robin-w

    there should be an error message at the top saying

    Your reply cannot be empty.

    but the other plugin may be affecting this.

    the quickest way to correct this is to create some content if it is blank.

    This filter (untested) will deal with empty content and add a space character.

    add_filter ('bbp_new_reply_pre_content' , 'rew_allow_blank_content') ;
    
    function rew_allow_blank_content ($reply_content) {
    	if ( empty( $reply_content ) ) {
    		$reply_content = ' ' ;
    	}
    return $reply_content ;
    }

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets

    I have initially set it to change empty content to a single space character ie

    $reply_content = ' ' ;

    however later checking by WordPress may delete this, so it may need some actual text – maybe like

    $reply_content = 'this reply is has no text' ;


    bhkh
    Participant

    @bhkh

    Thank you so much for such a fast and helpful reply!

    I must hang my head in shame and admit that I had inadvertently hidden the error message. How many times do I have to read “remove all plugins and use default theme” before I remember to do it completely every time.

    The UX for the error message is not great, especially on a smaller laptop screen. The message is hidden below the fold upon refresh. I wonder why there can’t be validation before the submit button is clicked.

    However, you solved the bigger problem of being able to submit a reply with only an attachment. I had thought about a solution like you proposed but had no idea how to do it.

    Thanks again!


    Robin W
    Moderator

    @robin-w

    I must hang my head in shame and admit that I had inadvertently hidden the error message. How many times do I have to read “remove all plugins and use default theme” before I remember to do it completely every time.

    🙂 🙂

    great – glad you are fixed 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar