How to enable truly anonymous posting in bbPress forums? [closed]

When we post an empty anonymous reply, we get the following errors:

errrors

The part of BBPress that’s responsible for handling this, is the bbp_new_reply_handler() function, in the file /bbpress/includes/replies/functions.php. It contains these lines that are of interest to us:

    // User is anonymous
    if ( bbp_is_anonymous() ) {

            // Filter anonymous data
            $anonymous_data = bbp_filter_anonymous_post_data();

where bbp_filter_anonymous_post_data() is defined in the file /bbpress/includes/replies/functions.php.

Here’s a demo plugin that should

  • allow you to post a reply with empty names and emails.
  • still keep the flood checks per IP number.
  • not write cookies, that will pre fill the name and the email textbox.
  • give you Anonymous as the replier’s name.

where:

/**
 * Plugin Name: Empty Anonymous Replies in BBPress
 * Plugin URI: http://wordpress.stackexchange.com/a/133420/26350
 */

add_action( 'init', array( 'WPSE_Empty_Anonymous_Replies', 'init' ) );

class WPSE_Empty_Anonymous_Replies
{
        static protected $name="nobody";
        static protected $email="[email protected]";

        static public function init()
        {
            add_filter( 'bbp_filter_anonymous_post_data', 
                         array( __CLASS__, 'bbp_filter_anonymous_post_data' ),                    
                         11, 2 );
            add_filter( 'bbp_pre_anonymous_post_author_name', 
                         array( __CLASS__,  'bbp_pre_anonymous_post_author_name' ) );
            add_filter( 'bbp_pre_anonymous_post_author_email',  
                         array( __CLASS__, 'bbp_pre_anonymous_post_author_email' ) );
        }

        static public function bbp_filter_anonymous_post_data( $retval, $r )
        {
            if( self::$name === $r['bbp_anonymous_name'] 
                && self::$email === $r['bbp_anonymous_email'] )
            {   
                // reset the input to skip writing cookies 
                $retval = array();

                // trick to activate the IP flood check 
                $retval['bbp_anonymous_flood_check'] = '1';
            }       
            return $retval;
        }

        static public function bbp_pre_anonymous_post_author_name( $name )
        {
            remove_filter( current_filter(), array( __CLASS__, __FUNCTION__ ) );
            if( empty( $name ) )
                $name = self::$name;

            return $name;
        }

        static public function bbp_pre_anonymous_post_author_email( $email )
        {
            remove_filter( current_filter(), array( __CLASS__, __FUNCTION__ ) );
            if( empty( $email ) )
                $email = self::$email;

            return $email;
        }
    }

I hope this can point you in the right direction.