Implementing v3 ReCaptcha to the s2member pro login widget

A few people have asked over the years about adding ReCaptcha to s2member pro login widget and I’m happy to say that after a little trial and error I’ve managed to ge it working.

My solution requires a readily available plugin and a one line addition to a s2member-pro file.

https://wordpress.org/plugins/invisible-recaptcha/

and after you’ve installed and configured this plugin with v3 recaptcha you can add the following line of code

do_action('google_invre_render_widget_action');

to at any line between line 128 and 155 of the following file

s2member-pro/src/includes/classes/login-widget.inc.php

Personally I add it between line 150 and 151

echo '<div class="ws-plugin--s2member-pro-login-widget-submit">'."\n";
if($redirect_to) echo '<input type="hidden" name="redirect_to" value="'.esc_attr($redirect_to).'" />'."\n".

like so

echo '<div class="ws-plugin--s2member-pro-login-widget-submit">'."\n";
do_action('google_invre_render_widget_action');
if($redirect_to) echo '<input type="hidden" name="redirect_to" value="'.esc_attr($redirect_to).'" />'."\n".

So if you choose to have an inline recaptcha it looks like this.

Inline

That should be it, enjoy!