Created
November 15, 2018 01:34
-
-
Save JohnTendik/33ded7e654e171af32399f9f5c2a98c9 to your computer and use it in GitHub Desktop.
Buddypress "I am not a robot" Recapche for registeration form
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 | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
if ( ! function_exists( 'jt_add_recaptcha_on_registeration' ) ) { | |
add_action( 'bp_signup_profile_fields', 'jt_add_recaptcha_on_registeration' ); | |
function jt_add_recaptcha_on_registeration() { | |
do_action('bp_recaptcha_errors'); | |
echo "<script src='https://www.google.com/recaptcha/api.js'></script>"; | |
echo '<div required class="g-recaptcha" data-sitekey="SITEKEYHERE"></div>'; | |
} | |
} | |
if ( ! function_exists( 'jt_recaptcha_validata' ) ) { | |
add_action( 'bp_signup_pre_validate', 'jt_recaptcha_validata' ); | |
function jt_recaptcha_validata() { | |
$bp = buddypress(); | |
$recaptcha_response = isset($_POST['g-recaptcha-response']) && $_POST['g-recaptcha-response'] != '' ? $_POST['g-recaptcha-response'] : false; | |
if (!$recaptcha_response) { | |
$bp->signup->errors['recaptcha'] = 'Capcha was left blank. Please complete the capcha.'; | |
} | |
CONTACT GOOGLE SERVER HERE THEN RETURN IF RESPONSE IS NOT SUCCESSFUL | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment