Incorrect call of JavaScript resource parameter
-
In a shop where I use the plugin to display two reCAPTCHAs on the ‘My Account’ page (one for logging in and one for registering), I received the following error message in the developer console:
reCAPTCHA render error: Error: reCAPTCHA has already been rendered in this element, line 45 in rcfwc.jsThe problem appears to be multifaceted. Firstly, the api.js file is enqueued as follows:
wp_enqueue_script( 'recaptcha', 'https://www.google.com/recaptcha/api.js?explicit&hl=' . get_locale(), array(), null, array('strategy' => 'defer'));According to the documentation, the parameter needs to be set up like this if you want to explicitly render the widgets (the code above is missing the render key):
'https://www.google.com/recaptcha/api.js?render=explicit'This most likely ensures that the default is used (onload), which will render all .g-recaptcha elements automatically.
So, if you have an existing wp object on a page and integrate reCAPTCHA, this will result in the reCAPTCHA being rendered twice: once by Google and once by the plugin’s JavaScript.
In my case, the wp object and the wp.data object are also defined on the ‘My Account’ page. This means that the check for wp and wp.data returns true, and the code within the if block is executed.
Adding the missing render key to the api.js URL appears to solve the issue at checkout, but not on the ‘My Account’ page. If wp and wp.data are not present, no reCAPTCHA is displayed on the ‘My Account’ page at all. If they are present, only the first one is displayed.
So the api.js call, like the handling of several recpactchas, probably needs to be adapted.
The topic ‘Incorrect call of JavaScript resource parameter’ is closed to new replies.