[MOD] add recaptcha to the membership registration page

I was able to manually add reCapatcha to the membership registration page. I am using BP, but I believe this would work for non BP. I am a hack and slash coder, so if someone knows how to clean it up, feel free and share. Also this seems easy to be built into the membership plugin it self with an option to turn it on an off in the settings page, but im just hard coding it on.

1.) sign up for reCapatcha at http://www.google.com/recaptcha

2.) remember you public and private keys

3. download the reCaptcha library file to use on your server here (you just want recaptchalib.php)

http://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest

4.) Copy recaptchalib.php to

wwwwp-contentpluginsmembershipmembershipincludesincludesrecaptchalib.php

5.) the check file that the registration form uses is

wwwwp-contentpluginsmembershipmembershipincludesmembershippublic.php

6.) the buddy press registration file is here

wwwwp-contentpluginsmembershipmembershipincludesincludesbp.registration.form.php

7.) open membershippublic.php

8.) Find

<?php do_action( 'bp_before_registration_submit_buttons' ) ?>

9.) on a new line under that, paste. Make sure to paste in your public key

<html>
<body>

<?php
require_once('recaptchalib.php');
$publickey = "PASTE YOUR PUBLIC KEY"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>

</body>
</html>

10.) in membershippublic.php you will see the “case” “validatepage1bp” (if you are not using BP I think yours would be “validatepage1”:wink: in that case you will find the code below, find it and delete it

$error = new WP_Error();

11.) in that same case right below “case ‘validatepage1bp’:” (if you are not using BP I think yours would be “validatepage1”:wink: paste the code below, so its pretty much the first thing the case does, and it will be above the code that was there originally. Make sure to put in your “PRIVATE KEY” and whatever your path is to “recaptchalib.php”

//TAO adding captcha to membership page for the membership plugin START
$error = new WP_Error();

require_once('/home/USERNAME/public_html/wp-content/plugins/membership/membershipincludes/includes/recaptchalib.php');

$privatekey = "PASTE YOUR PROVATE KEY";

$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
$error->add('passmatch', __('You did not fill out the captcha correctly - please try again'));
} else {
// Your code here to handle a successful verification
}
//TAO adding captcha to membership page for the membership plugin STOP