public
Last active

  • Download Gist
create-the-field.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?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>';
}
validate-the-input.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.