Remove the parameter onload from reCaptcha script URL
When is reCaptcha rendered with onload callback, sometimes the callback isn't defined yet due to race condition [MAILPOET-3390]
This commit is contained in:
@@ -18,7 +18,7 @@ class AssetsController {
|
|||||||
/** @var SettingsController */
|
/** @var SettingsController */
|
||||||
private $settings;
|
private $settings;
|
||||||
|
|
||||||
const RECAPTCHA_API_URL = 'https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit';
|
const RECAPTCHA_API_URL = 'https://www.google.com/recaptcha/api.js?render=explicit';
|
||||||
|
|
||||||
public function __construct(WPFunctions $wp, BasicRenderer $renderer, SettingsController $settings) {
|
public function __construct(WPFunctions $wp, BasicRenderer $renderer, SettingsController $settings) {
|
||||||
$this->wp = $wp;
|
$this->wp = $wp;
|
||||||
@@ -32,15 +32,15 @@ class AssetsController {
|
|||||||
*/
|
*/
|
||||||
public function printScripts() {
|
public function printScripts() {
|
||||||
ob_start();
|
ob_start();
|
||||||
$this->wp->wpPrintScripts('jquery');
|
|
||||||
$this->wp->wpPrintScripts('mailpoet_vendor');
|
|
||||||
$this->wp->wpPrintScripts('mailpoet_public');
|
|
||||||
|
|
||||||
$captcha = $this->settings->get('captcha');
|
$captcha = $this->settings->get('captcha');
|
||||||
if (!empty($captcha['type']) && $captcha['type'] === Captcha::TYPE_RECAPTCHA) {
|
if (!empty($captcha['type']) && $captcha['type'] === Captcha::TYPE_RECAPTCHA) {
|
||||||
echo '<script src="' . self::RECAPTCHA_API_URL . '" async defer></script>';
|
echo '<script src="' . self::RECAPTCHA_API_URL . '" async defer></script>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->wp->wpPrintScripts('jquery');
|
||||||
|
$this->wp->wpPrintScripts('mailpoet_vendor');
|
||||||
|
$this->wp->wpPrintScripts('mailpoet_public');
|
||||||
|
|
||||||
$scripts = ob_get_contents();
|
$scripts = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
if ($scripts === false) {
|
if ($scripts === false) {
|
||||||
@@ -61,6 +61,14 @@ class AssetsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setupFrontEndDependencies() {
|
public function setupFrontEndDependencies() {
|
||||||
|
$captcha = $this->settings->get('captcha');
|
||||||
|
if (!empty($captcha['type']) && $captcha['type'] === Captcha::TYPE_RECAPTCHA) {
|
||||||
|
$this->wp->wpEnqueueScript(
|
||||||
|
'mailpoet_recaptcha',
|
||||||
|
self::RECAPTCHA_API_URL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$this->wp->wpEnqueueStyle(
|
$this->wp->wpEnqueueStyle(
|
||||||
'mailpoet_public',
|
'mailpoet_public',
|
||||||
Env::$assetsUrl . '/dist/css/' . $this->renderer->getCssAsset('mailpoet-public.css')
|
Env::$assetsUrl . '/dist/css/' . $this->renderer->getCssAsset('mailpoet-public.css')
|
||||||
@@ -74,15 +82,6 @@ class AssetsController {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$captcha = $this->settings->get('captcha');
|
|
||||||
if (!empty($captcha['type']) && $captcha['type'] === Captcha::TYPE_RECAPTCHA) {
|
|
||||||
$this->wp->wpEnqueueScript(
|
|
||||||
'mailpoet_recaptcha',
|
|
||||||
self::RECAPTCHA_API_URL,
|
|
||||||
['mailpoet_public']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->wp->wpLocalizeScript('mailpoet_public', 'MailPoetForm', [
|
$this->wp->wpLocalizeScript('mailpoet_public', 'MailPoetForm', [
|
||||||
'ajax_url' => $this->wp->adminUrl('admin-ajax.php'),
|
'ajax_url' => $this->wp->adminUrl('admin-ajax.php'),
|
||||||
'is_rtl' => (function_exists('is_rtl') ? (bool)is_rtl() : false),
|
'is_rtl' => (function_exists('is_rtl') ? (bool)is_rtl() : false),
|
||||||
|
Reference in New Issue
Block a user