Skip to:
Content
Pages
Categories
Search
Top
Bottom

simple reCaptcha for Buddypress /register page

  • Avatar of NoahY
    NoahY
    Member

    @noahy

    After some fiddling, copying, more fiddling, I think I’ve got a working reCaptcha code. As it is, you just put this code in your theme’s functions.php file (I just made a child theme of the bp-default), edit the code to add a link to the recaptchalib.php file (get it here: http://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest ) and your public and private keys, and you’re good to go. Here’s the code:

    <?php
    require_once(‘/path/to/recaptchalib.php’);

    function bpn_add_reg_field() {
    global $bp;
    $publickey = “”;
    echo recaptcha_get_html($publickey);
    if ( !empty( $bp->signup->errors)) {
    echo $bp->signup->errors;
    }
    }

    function bpn_check_reg_recaptcha($errors)
    {
    global $bp;
    $private_key = “”;

    if (function_exists(‘recaptcha_check_answer’))
    {
    $response = recaptcha_check_answer($private_key, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);

    if (!$response->is_valid)
    {
    $bp->signup->errors = __( ‘ERROR: Captcha response is either empty or incorrect.’,’buddypress’);
    }
    }

    return ;
    }

    add_action( ‘bp_before_registration_submit_buttons’, ‘bpn_add_reg_field’ );
    add_action(‘bp_signup_validate’, ‘bpn_check_reg_recaptcha’ );

    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Avatar of NoahY
    NoahY
    Member

    @noahy

    The only problem I have with this is in Firefox I need to add css to put the div in the right place:

    #recaptcha_widget_div {
    clear:both;
    }

    does the trick.

    Avatar of NoahY
    NoahY
    Member

    @noahy

    I also use BWP-recaptcha for my other blogs on the network, so I can access the pub and priv keys from there, like so:

    global $bwp_capt;
    $publickey = $bwp_capt->options;

    and

    global $bwp_capt;
    $private_key = $bwp_capt->options;

    That way the keys are kept in one place.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.