Code change suggestion for V3
-
For V3, Google recommends calling execute when the user takes the action rather than on page load. The current code adds an event listener to the form but the listener isn’t working properly. The code sets the token on page load and it refreshes the token every two minutes.
Because most site visitors don’t login, register, or submit a comment, this wastes many calls to generate the token. You also get this warning in V3 admin console “We detected that your site is not verifying reCAPTCHA tokens. Please see our developer site for more information.” because the wasted tokens are not sent back to Google for verification.
I suggest this code change in public/inc/class-stlsr-captcha.php for V3:
43a44 > e.preventDefault(); 45a47,48 > // form.submit() doesn't work when the name of the submit button is 'submit' > HTMLFormElement.prototype.submit.call(form); 48,56d50 < function lsSetToken(action) { < if(action) { < grecaptcha.execute('$grecaptcha_v3_site_key', {action: action}).then(function(token) { < document.getElementById('g-recaptcha-response-' + action).value = token; < }); < } < } < lsSetToken(action); < setInterval(function() { lsSetToken(action); }, (2 * 60 * 1000));
Thank you for considering it.
- The topic ‘Code change suggestion for V3’ is closed to new replies.