My 2nd tier support team did some investigation and found a possible workaround for the Forgot Password form. It requires adding a custom PHP snippet that injects the same code injected by the Simple Google reCAPTCHA plugin . You can add this code in a child theme's functions.php file. Or, you can create a new code snippet in Toolset > Settings > Custom Code, set the snippet to run everywhere, and activate the snippet.
/**
* Forgot password form customisation
* Toolset support reference: https://toolset.com/forums/topic/password-reset-page/
*/
add_filter( 'forgot_password_form_middle', 'ts_forgot_password_form_middle', 101, 1 );
function ts_forgot_password_form_middle( $middle ){
$middle .= '<div class="sgr-main"></div>';
// From Simple Google Recaptcha plugin
$apiUrlBase = sprintf('<em><u>hidden link</u></em>', get_locale());
$jsUrl = sprintf('%s&onload=sgr_2&render=explicit', $apiUrlBase);
wp_enqueue_script('sgr_recaptcha', $jsUrl, [], time());
return $middle;
}
Here is the technical analysis:
I looked into our code to see how the forgot password form is generated and checked what the plugin is doing, and because they have fundamentally different approaches to outputting the form content and recaptcha fields there isn’t a simple fix involving triggering the lostpassword_form action in the right place.
Because we implement the form via a shortcode, that means that we build the entirety of the form as a string, then the shortcode returns that string, which then outputs it (i.e. adds the markup to the page).
It *is* possible to intervene in the process of constructing that string to insert some additional content.
But the plugin uses the lostpassword_form hook to insert the markup required for the recaptcha field by *echoing* it, i.e. dropping it into the markup for the page at that very point, rather than returning it is a string which can be added to the string being constructed with the form markup.
So triggering that lostpassword_form hook to insert the recaptcha could only ever be done directly before the form is built, or after, never during.
I do have a solution, though, which uses a filter for the middle part of the form (before the submit button) to add the markup required by the plugin and enqueue the script needed, too.
This is specifically for the forgot password form, if you needed to get this working with other log in forms it would require variations on the same solution using different filters