Last active
July 13, 2023 22:07
-
-
Save jessuppi/0663069e94af7f397510990ccd576a30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Anonymize bbPress | |
Plugin URI: https://gist.github.com/jessuppi/0663069e94af7f397510990ccd576a30 | |
Description: Enables guest users to participate in bbPress forums without providing an email address or URL, and assigns randomized user names to every single post. | |
Version: 1.0.0 | |
Author: Birgir Erlendsson, Jesse Nickles | |
License: GPLv3 | |
License URI: https://www.gnu.org/licenses/gpl-3.0.html | |
*/ | |
$random_names_list = array("John", "Mike", "Will", "Pete", "Lucy", "Barbara"); | |
$random_name = $random_names_list[array_rand($random_names_list)]; | |
add_action( 'init', array( 'WPSE_Empty_Anonymous_Replies', 'init' ) ); | |
class WPSE_Empty_Anonymous_Replies | |
{ | |
static protected $name = 'nobody'; // $random_name | |
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; | |
} | |
} | |
// load dummy stylesheet | |
wp_register_style('anonymize_bbpress_styles', false); | |
wp_enqueue_style('anonymize_bbpress_styles'); | |
// add some inline CSS rules to hide fields | |
wp_add_inline_style('anonymize_bbpress_styles', 'fieldset.bbp-form label,input { display:none !important; }'); | |
// Ref: https://wordpress.stackexchange.com/questions/131550/how-do-i-set-up-real-anonymous-posting-in-bbpress-forums | |
// Ref: https://developer.wordpress.org/reference/functions/wp_add_inline_style/ | |
// Ref: https://gist.github.com/neilgee/bdf621baa3d535c97d9d | |
// Ref: https://wordpress.stackexchange.com/questions/168867/using-wp-add-inline-style-without-a-stylesheet | |
// Ref: https://wordpress.stackexchange.com/questions/408851/how-to-add-some-basic-inline-css-using-existing-plugin-or-theme | |
// Ref: https://randomtechnofestivalnamegenerator.nl/how-to-make-a-random-generator-with-php/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment