Skip to content

Instantly share code, notes, and snippets.

@brandondove
Created September 19, 2012 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brandondove/3748153 to your computer and use it in GitHub Desktop.
Save brandondove/3748153 to your computer and use it in GitHub Desktop.
<?php
// Hook into the BuddyPress registration form
add_action( 'bp_after_signup_profile_fields', 'add_honeypot' );
/**
* Add a hidden text input that users won't see
* so it should always be empty. If it's filled out
* we know it's a spambot or some other hooligan
*/
function add_honeypot() {
echo '<div style="display: none;">';
echo '<input type="text" name="oh_no_you_dint" id="sucka" />';
echo '</div>';
}
<?php
// Validate the input
add_filter( 'bp_core_validate_user_signup', 'check_honeypot' );
/**
* Check to see if the honeypot field has a value.
* If it does, return an error
*/
function check_honeypot( $result = array() ) {
global $bp;
if( isset( $_POST['oh_no_you_dint'] ) && !empty( $_POST['oh_no_you_dint'] ) )
$result['errors']->add( 'pjbp_honeypot', __( "You're totally a spammer. Go somewhere else with your spammy ways." ) );
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment