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.

I have bbpress-post-topics plugin installed so that my comments forms are replaced by a bbpress forum topic, it's working but I would like to enable anonymous posting.

how do i remove the fields so users can post anonymously?

Currently, as you can see above, the Author Name, Email, Website and Topic Title are required. I would like to adjust this so only the 'topic title' is required and if they are not logged in, their posts are attributed to a user called 'anonymous'

I can edit the PHP if required - I really thought the setting in Forums for 'Allow guest users without accounts to create topics and replies' would have achieved what I'm aiming for.

Note: This problem exists in the traditional forums too, e.g.

http://www.rugbydata.com/forums/forum/aviva-premiership/

You can see the author name/email are required fields.

How do I remove them as required fields so users can really post anonymously without creating an account?

share|improve this question

1 Answer 1

up vote 4 down vote accepted
+50

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 = 'nobody@example.com';

        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.

share|improve this answer
    
So where do we put this code, some might ask?: This is a plugin, so we can create a file like /wp-content/plugins/empty-anonymous-replies-in-bbpress/empty-anonymous-replies-‌​in-bbpress.php. Then we visit the plugin section in the backend and activate it. This code should also work from the functions.php file in the current theme directory. I hope this helps the users, that aren't sure what to do with this code. –  birgire Jun 10 at 22:34

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.