Created
September 19, 2012 07:20
-
-
Save brandondove/3748153 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// 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>'; | |
} |
This file contains hidden or 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 | |
// 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