Support » Plugin: GiveWP - Donation Plugin and Fundraising Platform » Donations login and recaptcha

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter IncognitoCEO

    (@incognitoceo)

    * To effectively use this snippet, please do the following:
    * 1. Get your Google ReCAPTCHA API Key here: https://www.google.com/recaptcha/
    * 2. In each function and action, replace “_myprefix_” with your own custom prefix
    * 3. Put your “Secret Key” where it says “MYSECRETKEY” in the $recaptcha_secret_key string
    * 4. Put your “Site Key” where it says “MYSITEKEY” in TWO areas below

    Hey so i figured this out except for one thing. It says to add my own custom prefix. _myprefix_ I’m not sure where to get this custom prefix. Or do i just make up any word? Also, do i leave the underscore before and after?

    Warmly, Chuck

    Postscript-I zoomed with Amanda this morning and she is fabuloso!

    Thread Starter IncognitoCEO

    (@incognitoceo)

    This didn’t work. The prefix i added was made up. _amsynd_ I used the custom functions plugin. I changed some of the keys so i’m not posting the exact key here for safety.

    <?php
    /**
    * Implementing Google’s ReCaptcha on All Give Forms
    *
    * To effectively use this snippet, please do the following:
    * 1. Get your Google ReCAPTCHA API Key here: https://www.google.com/recaptcha/
    * 2. In each function and action, replace “_amsynd_” with your own custom prefix
    * 3. Put your “Secret Key” where it says “MYSECRETKEY” in the $recaptcha_secret_key string
    * 4. Put your “Site Key” where it says “MYSITEKEY” in TWO areas below
    */
    /**
    * Validate ReCAPTCHA
    *
    * @param $valid_data
    * @param $data
    *
    * @return array $valid_data
    */
    function give_amsynd_validate_recaptcha( $valid_data, $data ) {
    $recaptcha_url = ‘https://www.google.com/recaptcha/api/siteverify&#8217;;
    $recaptcha_secret_key = ‘MYSECRETKEY’; // 6LrtXRYXMLVIRUSCOmKzgSQ94lc1234FGPbDqI4h $recaptcha_response = wp_remote_post( $recaptcha_url . ‘?secret=’ . $recaptcha_secret_key . ‘&response=’ . $data[‘g-recaptcha-response’] . ‘&remoteip=’ . $_SERVER[‘REMOTE_ADDR’] );
    $recaptcha_data = wp_remote_retrieve_body( $recaptcha_response );
    if ( ! isset( $recaptcha_data->success ) && ! $recaptcha_data->success == true ) {
    // User must have validated the reCAPTCHA to proceed with donation.
    if ( ! isset( $data[‘g-recaptcha-response’] ) || empty( $data[‘g-recaptcha-response’] ) ) {
    give_set_error( ‘g-recaptcha-response’, __( ‘Please verify that you are not a robot.’, ‘give’ ) );
    }
    }
    return $valid_data;
    }
    add_action( ‘give_checkout_error_checks’, ‘give_amsynd_validate_recaptcha’, 10, 2 );
    /**
    * Enqueue ReCAPTCHA Scripts
    */
    function give_amsynd_recaptcha_scripts() {
    wp_register_script( ‘give-captcha-js’, ‘https://www.google.com/recaptcha/api.js&#8217; );
    // If you only want to enqueue on single form pages then uncomment if statement
    // if ( is_singular( ‘give_forms’ ) ) {
    wp_enqueue_script( ‘give-captcha-js’ );
    // }
    }
    add_action( ‘wp_enqueue_scripts’, ‘give_amsynd_recaptcha_scripts’ );
    /**
    * Print Necessary Inline JS for ReCAPTCHA
    *
    * This function outputs the appropriate inline js ReCAPTCHA scripts in the footer
    */
    function give_amsynd_print_my_inline_script() {
    // Uncomment if statement to control output
    // if ( is_singular( ‘give_forms’ ) ) {
    ?>
    <script type=”text/javascript”>
    jQuery( document ).on( ‘give_gateway_loaded’, function() {
    grecaptcha.render( ‘give-recaptcha-element’, {
    ‘sitekey’: ‘MYSITEKEY’ // 6LxmlvirusXRERFLDSGHJnnwBX67Z60Dnof_voTTcCsBk } );
    } );
    </script>
    <?php
    // }
    }
    add_action( ‘wp_footer’, ‘give_amsynd_print_my_inline_script’ );
    /**
    * Custom ReCAPTCHA Form Field
    *
    * This function adds the reCAPTCHA field above the “Donation Total” field.
    *
    * Don’t forget to update the sitekey!
    *
    * @param $form_id
    */
    function give_amsynd_custom_form_fields( $form_id ) {
    // 6LdmXRYXMLVIRUSnnwBX67Z7Dnof_voTTcCsBk
    ?>
    <div id=”give-recaptcha-element” class=”g-recaptcha” data-sitekey=”MYSITEKEY”
    style=”margin-bottom:1em”></div>
    <?php
    }
    add_action( ‘give_donation_form_before_submit’, ‘give_amsynd_custom_form_fields’, 10, 1 );

    Plugin Author Matt Cromwell

    (@webdevmattcrom)

    Hi there,

    This is the most comprehensive resource we have on fighting Donor Spam in general. Take a read through that, and go through those steps and let me know if you have additional questions at all.
    https://givewp.com/documentation/core/frequent-troubleshooting-issues/donor-spam-troubleshooting/

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Donations login and recaptcha’ is closed to new replies.