How do I set up real anonymous posting in bbpress forums? [closed]
IT Nursery
May 7, 2022
0
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.
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.
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?
1 Answer 1
When we post an empty anonymous reply, we get the following errors:
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;
}
}