Posted on 2 Comments

Google’s Invisible Recaptcha with MemberPress Plugin

MemberPress has a great Match Captcha add-on included for free which works great for helping to prevent SPAM signups through MemberPress.

But what if you want something that works with more forms/plugins than just MemberPress?

There’s a great, free plugin called Invisible reCaptcha for WordPress that works with many popular plugins out of the box, and is not too hard to integrate with others.

In this post I’ll show you how to get it working with MemberPress.

First you’ll want to install the following two plugins:

  1. Invisible reCaptcha for WordPress
  2. Code Snippets

Next you’ll need to register for Google’s Invisible reCaptcha here: https://www.google.com/recaptcha/intro/invisible.html

After registering your site, you’ll be given a Site Key and a Secret Key that you’ll need to copy into the plugin’s settings page like so:

Configure the rest of the Invisible reCaptcha plugin as you wish. You’ll notice there’s no option there for MemberPress. As the plugin doesn’t have support for MemberPress included yet, we’ll need to integrate it ourselves with a little bit of code.

So, copy the following code and paste it into a new Snippet in the Code Snippets plugin.

// Integrates MemberPress with Invisible reCaptcha
function add_invisible_recaptcha_mepr_signup($membership_ID) {
  ?>
    <div class="mp-form-row mepr_invisible_recaptcha">
      <?php do_action('google_invre_render_widget_action'); ?>
    </div>
  <?php
}
add_filter('mepr-checkout-before-submit', 'add_invisible_recaptcha_mepr_signup');

function validate_invisible_recaptcha_mepr_signup($errors) {
  $is_valid = apply_filters('google_invre_is_valid_request_filter', true);
  if(!$is_valid) {
    $errors[] = "Failed Captcha";
  }
  return $errors;
}
add_filter('mepr-validate-signup', 'validate_invisible_recaptcha_mepr_signup');

It should look like this:

That’s it! Now you’ll have Invisible reCaptcha on your MemberPress registration forms like this:

2 thoughts on “Google’s Invisible Recaptcha with MemberPress Plugin

  1. I followed the instructions and it creates an issue when a user signs up. With this enabled, upon signing up for a paid membership, the payment goes through fine, the user’s account is created, and welcome/admin emails are sent, but it doesn’t log them in correctly or send them to the thank you page. Instead I remain on the purchase page and receive this error:

    ###
    ERROR: This email address has already been used. If you are an existing user, please Login to complete your purchase. You will be redirected back here to complete your sign-up afterwards.
    ###

    If I log in, everything is fine. But this will obviously confuse any new members and it appears as if it failed. I’ve tried this three times on 2 separate memberships. The problem stops when I disable the Invisible reCaptcha plug-in.

    Any idea why?

    1. Carl, that sounds like you’re trying to make a purchase with an email address that already existed on your site. Try logging in first, or using an email address that doesn’t exist.

Leave a Reply

Your email address will not be published. Required fields are marked *