• Resolved hellok38

    (@hellok38)


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author ScriptsTown

    (@scriptstown)

    Hi,

    We have improved our code in the new version so it will generate the token on user action instead of page load.

    You can update the plugin to version 1.3.6.

    Thanks for your suggestion!

    Thread Starter hellok38

    (@hellok38)

    Thank you for the fast release. May I offer another suggestion? Most of the bot submissions have g-recaptcha-response set to an empty string. We don’t need to verify with Google to know it’s invalid. If we add a check for the empty token, we save a call to Google and also avoid filling the error log with repeated bot submissions.

    Plugin Author ScriptsTown

    (@scriptstown)

    Thanks for pointing it out. I will fix that in the next update (very soon).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Code change suggestion for V3’ is closed to new replies.