-
-
Save jessuppi/fa339e5b0e43cbd714c64b0680c2d99f to your computer and use it in GitHub Desktop.
WordPress plugin: BBPMods Anonymous
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 | |
* Description: bbPress anonymous modifications. | |
* Version: 0.0.2 | |
* Requires PHP: 5.4 | |
*/ | |
/** | |
* Changelog. | |
* | |
* 0.0.2 Fixed formatting. | |
* Added changelog. | |
* 0.0.1 Init. | |
*/ | |
namespace BBPMods\Anonymous; | |
/** | |
* Init. | |
*/ | |
add_action( 'init', function(){ | |
add_filter( 'bbp_current_user_can_access_anonymous_user_form', '__return_false' ); | |
$anonymous_users = array( | |
array ( 'Aaron', '[email protected]' ), | |
array ( 'Abigail', '[email protected]' ), | |
array ( 'Adam', '[email protected]' ), | |
array ( 'Alan', '[email protected]' ), | |
array ( 'Albert', '[email protected]' ), | |
array ( 'Alexander', '[email protected]' ), | |
array ( 'Alexis', '[email protected]' ), | |
array ( 'Alice', '[email protected]' ), | |
array ( 'Amanda', '[email protected]' ), | |
array ( 'Amber', '[email protected]' ), | |
array ( 'Amy', '[email protected]' ), | |
array ( 'Andrea', '[email protected]' ), | |
array ( 'Andrew', '[email protected]' ), | |
array ( 'Angela', '[email protected]' ), | |
array ( 'Ann', '[email protected]' ), | |
array ( 'Anna', '[email protected]' ), | |
array ( 'Anthony', '[email protected]' ), | |
array ( 'Arthur', '[email protected]' ), | |
array ( 'Ashley', '[email protected]' ), | |
array ( 'Austin', '[email protected]' ), | |
array ( 'Barbara', '[email protected]' ), | |
array ( 'Benjamin', '[email protected]' ), | |
array ( 'Betty', '[email protected]' ), | |
array ( 'Beverly', '[email protected]' ), | |
array ( 'Billy', '[email protected]' ), | |
array ( 'Bobby', '[email protected]' ), | |
array ( 'Brandon', '[email protected]' ), | |
array ( 'Brenda', '[email protected]' ), | |
array ( 'Brian', '[email protected]' ), | |
array ( 'Brittany', '[email protected]' ), | |
array ( 'Bruce', '[email protected]' ), | |
array ( 'Bryan', '[email protected]' ), | |
array ( 'Carl', '[email protected]' ), | |
array ( 'Carol', '[email protected]' ), | |
array ( 'Carolyn', '[email protected]' ), | |
array ( 'Catherine', '[email protected]' ), | |
array ( 'Charles', '[email protected]' ), | |
array ( 'Charlotte', '[email protected]' ), | |
array ( 'Cheryl', '[email protected]' ), | |
array ( 'Christian', '[email protected]' ), | |
array ( 'Christina', '[email protected]' ), | |
array ( 'Christine', '[email protected]' ), | |
array ( 'Christopher', '[email protected]' ), | |
array ( 'Cynthia', '[email protected]' ), | |
array ( 'Daniel', '[email protected]' ), | |
array ( 'Danielle', '[email protected]' ), | |
array ( 'David', '[email protected]' ), | |
array ( 'Deborah', '[email protected]' ), | |
array ( 'Debra', '[email protected]' ), | |
array ( 'Denise', '[email protected]' ), | |
array ( 'Dennis', '[email protected]' ), | |
array ( 'Diana', '[email protected]' ), | |
array ( 'Diane', '[email protected]' ), | |
array ( 'Donald', '[email protected]' ), | |
array ( 'Donna', '[email protected]' ), | |
array ( 'Doris', '[email protected]' ), | |
array ( 'Dorothy', '[email protected]' ), | |
array ( 'Douglas', '[email protected]' ), | |
array ( 'Dylan', '[email protected]' ), | |
array ( 'Edward', '[email protected]' ), | |
array ( 'Elijah', '[email protected]' ), | |
array ( 'Elizabeth', '[email protected]' ), | |
array ( 'Emily', '[email protected]' ), | |
array ( 'Emma', '[email protected]' ), | |
array ( 'Eric', '[email protected]' ), | |
array ( 'Ethan', '[email protected]' ), | |
array ( 'Eugene', '[email protected]' ), | |
array ( 'Evelyn', '[email protected]' ), | |
array ( 'Frances', '[email protected]' ), | |
array ( 'Frank', '[email protected]' ), | |
array ( 'Gabriel', '[email protected]' ), | |
array ( 'Gary', '[email protected]' ), | |
array ( 'George', '[email protected]' ), | |
array ( 'Gerald', '[email protected]' ), | |
array ( 'Gloria', '[email protected]' ), | |
array ( 'Grace', '[email protected]' ), | |
array ( 'Gregory', '[email protected]' ), | |
array ( 'Hannah', '[email protected]' ), | |
array ( 'Harold', '[email protected]' ), | |
array ( 'Heather', '[email protected]' ), | |
array ( 'Helen', '[email protected]' ), | |
array ( 'Henry', '[email protected]' ), | |
array ( 'Isabella', '[email protected]' ), | |
array ( 'Jack', '[email protected]' ), | |
array ( 'Jacob', '[email protected]' ), | |
array ( 'Jacqueline', '[email protected]' ), | |
array ( 'James', '[email protected]' ), | |
array ( 'Janet', '[email protected]' ), | |
array ( 'Janice', '[email protected]' ), | |
array ( 'Jason', '[email protected]' ), | |
array ( 'Jean', '[email protected]' ), | |
array ( 'Jeffrey', '[email protected]' ), | |
array ( 'Jennifer', '[email protected]' ), | |
array ( 'Jeremy', '[email protected]' ), | |
array ( 'Jerry', '[email protected]' ), | |
array ( 'Jesse', '[email protected]' ), | |
array ( 'Jessica', '[email protected]' ), | |
array ( 'Joan', '[email protected]' ), | |
array ( 'Joe', '[email protected]' ), | |
array ( 'John', '[email protected]' ), | |
array ( 'Jonathan', '[email protected]' ), | |
array ( 'Jordan', '[email protected]' ), | |
array ( 'Jose', '[email protected]' ), | |
array ( 'Joseph', '[email protected]' ), | |
array ( 'Joshua', '[email protected]' ), | |
array ( 'Joyce', '[email protected]' ), | |
array ( 'Juan', '[email protected]' ), | |
array ( 'Judith', '[email protected]' ), | |
array ( 'Judy', '[email protected]' ), | |
array ( 'Julia', '[email protected]' ), | |
array ( 'Julie', '[email protected]' ), | |
array ( 'Justin', '[email protected]' ), | |
array ( 'Karen', '[email protected]' ), | |
array ( 'Katherine', '[email protected]' ), | |
array ( 'Kathleen', '[email protected]' ), | |
array ( 'Kathryn', '[email protected]' ), | |
array ( 'Kayla', '[email protected]' ), | |
array ( 'Keith', '[email protected]' ), | |
array ( 'Kelly', '[email protected]' ), | |
array ( 'Kenneth', '[email protected]' ), | |
array ( 'Kevin', '[email protected]' ), | |
array ( 'Kimberly', '[email protected]' ), | |
array ( 'Kyle', '[email protected]' ), | |
array ( 'Larry', '[email protected]' ), | |
array ( 'Laura', '[email protected]' ), | |
array ( 'Lauren', '[email protected]' ), | |
array ( 'Lawrence', '[email protected]' ), | |
array ( 'Linda', '[email protected]' ), | |
array ( 'Lisa', '[email protected]' ), | |
array ( 'Logan', '[email protected]' ), | |
array ( 'Lori', '[email protected]' ), | |
array ( 'Louis', '[email protected]' ), | |
array ( 'Madison', '[email protected]' ), | |
array ( 'Margaret', '[email protected]' ), | |
array ( 'Maria', '[email protected]' ), | |
array ( 'Marie', '[email protected]' ), | |
array ( 'Marilyn', '[email protected]' ), | |
array ( 'Mark', '[email protected]' ), | |
array ( 'Martha', '[email protected]' ), | |
array ( 'Mary', '[email protected]' ), | |
array ( 'Mason', '[email protected]' ), | |
array ( 'Matthew', '[email protected]' ), | |
array ( 'Megan', '[email protected]' ), | |
array ( 'Melissa', '[email protected]' ), | |
array ( 'Michael', '[email protected]' ), | |
array ( 'Michelle', '[email protected]' ), | |
array ( 'Nancy', '[email protected]' ), | |
array ( 'Natalie', '[email protected]' ), | |
array ( 'Nathan', '[email protected]' ), | |
array ( 'Nicholas', '[email protected]' ), | |
array ( 'Nicole', '[email protected]' ), | |
array ( 'Noah', '[email protected]' ), | |
array ( 'Olivia', '[email protected]' ), | |
array ( 'Pamela', '[email protected]' ), | |
array ( 'Patricia', '[email protected]' ), | |
array ( 'Patrick', '[email protected]' ), | |
array ( 'Paul', '[email protected]' ), | |
array ( 'Peter', '[email protected]' ), | |
array ( 'Philip', '[email protected]' ), | |
array ( 'Rachel', '[email protected]' ), | |
array ( 'Ralph', '[email protected]' ), | |
array ( 'Randy', '[email protected]' ), | |
array ( 'Raymond', '[email protected]' ), | |
array ( 'Rebecca', '[email protected]' ), | |
array ( 'Richard', '[email protected]' ), | |
array ( 'Robert', '[email protected]' ), | |
array ( 'Roger', '[email protected]' ), | |
array ( 'Ronald', '[email protected]' ), | |
array ( 'Roy', '[email protected]' ), | |
array ( 'Russell', '[email protected]' ), | |
array ( 'Ruth', '[email protected]' ), | |
array ( 'Ryan', '[email protected]' ), | |
array ( 'Samantha', '[email protected]' ), | |
array ( 'Samuel', '[email protected]' ), | |
array ( 'Sandra', '[email protected]' ), | |
array ( 'Sara', '[email protected]' ), | |
array ( 'Sarah', '[email protected]' ), | |
array ( 'Scott', '[email protected]' ), | |
array ( 'Sean', '[email protected]' ), | |
array ( 'Sharon', '[email protected]' ), | |
array ( 'Shirley', '[email protected]' ), | |
array ( 'Sophia', '[email protected]' ), | |
array ( 'Stephanie', '[email protected]' ), | |
array ( 'Stephen', '[email protected]' ), | |
array ( 'Steven', '[email protected]' ), | |
array ( 'Susan', '[email protected]' ), | |
array ( 'Teresa', '[email protected]' ), | |
array ( 'Terry', '[email protected]' ), | |
array ( 'Theresa', '[email protected]' ), | |
array ( 'Thomas', '[email protected]' ), | |
array ( 'Timothy', '[email protected]' ), | |
array ( 'Tyler', '[email protected]' ), | |
array ( 'Victoria', '[email protected]' ), | |
array ( 'Vincent', '[email protected]' ), | |
array ( 'Virginia', '[email protected]' ), | |
array ( 'Walter', '[email protected]' ), | |
array ( 'Wayne', '[email protected]' ), | |
array ( 'William', '[email protected]' ), | |
array ( 'Willie', '[email protected]' ), | |
array ( 'Zachary', '[email protected]' ), | |
); | |
/** | |
* Filter anonymous users. | |
* | |
* @param array $anonymous_users Array of arrays with name and email. | |
*/ | |
$anonymous_users = apply_filters( 'bbpmods_anonymous_users', $anonymous_users ); | |
$obj = new Empty_Anonymous_Replies(); | |
$obj ->set_anonymous_users( $anonymous_users ) | |
->init(); | |
} ); | |
/** | |
* Class Empty_Anonymous_Replies. | |
* | |
* @since 0.0.1 | |
*/ | |
class Empty_Anonymous_Replies { | |
/** | |
* @var int | |
* | |
* @since 0.0.1 | |
*/ | |
protected $user_index = 0; | |
/** | |
* @var int | |
* | |
* @since 0.0.1 | |
*/ | |
protected $name_index = 0; | |
/** | |
* @var int | |
* | |
* @since 0.0.1 | |
*/ | |
protected $email_index = 1; | |
/** | |
* @var array | |
* | |
* @since 0.0.1 | |
*/ | |
protected $anonymous_users = array(); | |
/** | |
* Set anonymous users. | |
* | |
* @since 0.0.1 | |
* | |
* @param array $anonymous_users Array of arrays with name and email. | |
*/ | |
public function set_anonymous_users( $anonymous_users ) { | |
$this->anonymous_users = $anonymous_users; | |
return $this; | |
} | |
/** | |
* Init. | |
* | |
* @since 0.0.1 | |
*/ | |
public function init() { | |
// Filters in order of activation. | |
add_filter( 'bbp_before_filter_anonymous_post_data_parse_args', | |
array( $this, 'bbp_before_filter_anonymous_post_data_parse_args' ), | |
10 ); | |
add_filter( 'bbp_pre_anonymous_post_author_name', | |
array( $this, 'bbp_pre_anonymous_post_author_name' ) ); | |
add_filter( 'bbp_pre_anonymous_post_author_email', | |
array( $this, 'bbp_pre_anonymous_post_author_email' ) ); | |
add_filter( 'bbp_filter_anonymous_post_data', | |
array( $this, 'bbp_filter_anonymous_post_data' ), | |
11, 2 ); | |
} | |
/** | |
* Filter's callback | |
* | |
* @since 0.0.1 | |
* | |
* @param array $r Anonymous post data. | |
*/ | |
public function bbp_before_filter_anonymous_post_data_parse_args( $r ) { | |
if ( ! empty( $this->anonymous_users ) ) { | |
$this->user_index = array_rand( $this->anonymous_users ); | |
} | |
return $r; | |
} | |
/** | |
* Filter's callback | |
* | |
* @since 0.0.1 | |
* | |
* @param string $name Anonymous user's name. | |
*/ | |
public function bbp_pre_anonymous_post_author_name( $name ) { | |
remove_filter( current_filter(), array( $this, __FUNCTION__ ) ); | |
if( empty( $name ) && ! empty( $this->anonymous_users ) ) { | |
$name = $this->anonymous_users[$this->user_index][$this->name_index]; | |
} | |
return $name; | |
} | |
/** | |
* Filter's callback | |
* | |
* @since 0.0.1 | |
* | |
* @param string $email Anonymous user's email. | |
*/ | |
public function bbp_pre_anonymous_post_author_email( $email ) { | |
remove_filter( current_filter(), array( $this, __FUNCTION__ ) ); | |
if( empty( $email ) && ! empty( $this->anonymous_users ) ) { | |
$email = $this->anonymous_users[$this->user_index][$this->email_index]; | |
} | |
return $email; | |
} | |
/** | |
* Filter's callback | |
* | |
* @since 0.0.1 | |
* | |
* @param array $retval Anonymous post data. | |
* @param array $r Arguments. | |
*/ | |
public function bbp_filter_anonymous_post_data( $retval, $r ) { | |
if ( empty( $this->anonymous_users ) ) { | |
return $retval; | |
} | |
if( $this->anonymous_users[$this->user_index][$this->name_index] === $r['bbp_anonymous_name'] | |
&& $this->anonymous_users[$this->user_index][$this->email_index] === $r['bbp_anonymous_email'] | |
) { | |
// Reset the input to skip writing cookies. | |
$retval = array(); | |
// Activate the IP flood check. | |
$retval['bbp_anonymous_flood_check'] = '1'; | |
} | |
return $retval; | |
} | |
} | |
// Ref: https://www.ssa.gov/oact/babynames/decades/century.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment