Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../src/Frontend
File: Captcha.php
[500] Fix | Delete
$sync = /** @lang JavaScript */
[501] Fix | Delete
'const wpformsRecaptchaSync = ( func ) => {
[502] Fix | Delete
return function() {
[503] Fix | Delete
const context = this;
[504] Fix | Delete
const args = arguments;
[505] Fix | Delete
[506] Fix | Delete
// Sync with jQuery ready event.
[507] Fix | Delete
jQuery( document ).ready( function() {
[508] Fix | Delete
func.apply( context, args );
[509] Fix | Delete
} );
[510] Fix | Delete
}
[511] Fix | Delete
};
[512] Fix | Delete
';
[513] Fix | Delete
[514] Fix | Delete
if ( $captcha_settings['provider'] === 'hcaptcha' ) {
[515] Fix | Delete
$data = $dispatch;
[516] Fix | Delete
$data .= $callback;
[517] Fix | Delete
[518] Fix | Delete
$data .= /** @lang JavaScript */
[519] Fix | Delete
'var wpformsRecaptchaLoad = function () {
[520] Fix | Delete
Array.prototype.forEach.call(document.querySelectorAll(".h-captcha"), function (el) {
[521] Fix | Delete
var captchaID = hcaptcha.render(el, {
[522] Fix | Delete
callback: function () {
[523] Fix | Delete
wpformsRecaptchaCallback(el);
[524] Fix | Delete
}
[525] Fix | Delete
});
[526] Fix | Delete
el.setAttribute("data-recaptcha-id", captchaID);
[527] Fix | Delete
});
[528] Fix | Delete
wpformsDispatchEvent(document, "wpformsRecaptchaLoaded", true);
[529] Fix | Delete
};
[530] Fix | Delete
';
[531] Fix | Delete
[532] Fix | Delete
return $data;
[533] Fix | Delete
}
[534] Fix | Delete
[535] Fix | Delete
if ( $captcha_settings['provider'] === 'turnstile' ) {
[536] Fix | Delete
$data = $dispatch;
[537] Fix | Delete
$data .= $callback;
[538] Fix | Delete
$data .= $turnstile_update_class;
[539] Fix | Delete
[540] Fix | Delete
$data .= /** @lang JavaScript */
[541] Fix | Delete
'var wpformsRecaptchaLoad = function () {
[542] Fix | Delete
Array.prototype.forEach.call(document.querySelectorAll(".wpforms-turnstile"), function (el) {
[543] Fix | Delete
let form = el.closest( "form" ),
[544] Fix | Delete
formId = form.dataset.formid,
[545] Fix | Delete
captchaID = turnstile.render(el, {
[546] Fix | Delete
theme: "' . $captcha_settings['theme'] . '",
[547] Fix | Delete
callback: function () {
[548] Fix | Delete
turnstileUpdateContainer(el);
[549] Fix | Delete
wpformsRecaptchaCallback(el);
[550] Fix | Delete
},
[551] Fix | Delete
"timeout-callback": function() {
[552] Fix | Delete
turnstileUpdateContainer(el);
[553] Fix | Delete
}
[554] Fix | Delete
});
[555] Fix | Delete
el.setAttribute("data-recaptcha-id", captchaID);
[556] Fix | Delete
});
[557] Fix | Delete
[558] Fix | Delete
wpformsDispatchEvent( document, "wpformsRecaptchaLoaded", true );
[559] Fix | Delete
};
[560] Fix | Delete
';
[561] Fix | Delete
[562] Fix | Delete
return $data;
[563] Fix | Delete
}
[564] Fix | Delete
[565] Fix | Delete
if ( $captcha_settings['recaptcha_type'] === 'v3' ) {
[566] Fix | Delete
$data = $dispatch;
[567] Fix | Delete
[568] Fix | Delete
$data .= /** @lang JavaScript */
[569] Fix | Delete
'var wpformsRecaptchaV3Execute = function ( callback ) {
[570] Fix | Delete
grecaptcha.execute( "' . $captcha_settings['site_key'] . '", { action: "wpforms" } ).then( function ( token ) {
[571] Fix | Delete
Array.prototype.forEach.call( document.getElementsByName( "wpforms[recaptcha]" ), function ( el ) {
[572] Fix | Delete
el.value = token;
[573] Fix | Delete
} );
[574] Fix | Delete
if ( typeof callback === "function" ) {
[575] Fix | Delete
return callback();
[576] Fix | Delete
}
[577] Fix | Delete
} );
[578] Fix | Delete
}
[579] Fix | Delete
grecaptcha.ready( function () {
[580] Fix | Delete
wpformsDispatchEvent( document, "wpformsRecaptchaLoaded", true );
[581] Fix | Delete
} );
[582] Fix | Delete
';
[583] Fix | Delete
} elseif ( $captcha_settings['recaptcha_type'] === 'invisible' ) {
[584] Fix | Delete
$data = $polyfills;
[585] Fix | Delete
$data .= $dispatch;
[586] Fix | Delete
$data .= $sync;
[587] Fix | Delete
[588] Fix | Delete
$data .= /** @lang JavaScript */
[589] Fix | Delete
'var wpformsRecaptchaLoad = wpformsRecaptchaSync( function () {
[590] Fix | Delete
Array.prototype.forEach.call(document.querySelectorAll(".g-recaptcha"), function (el) {
[591] Fix | Delete
try {
[592] Fix | Delete
var recaptchaID = grecaptcha.render(el, {
[593] Fix | Delete
"callback": function () {
[594] Fix | Delete
wpformsRecaptchaCallback(el);
[595] Fix | Delete
},
[596] Fix | Delete
"error-callback": function () {
[597] Fix | Delete
wpformsRecaptchaErrorCallback(el);
[598] Fix | Delete
}
[599] Fix | Delete
}, true);
[600] Fix | Delete
el.closest("form").querySelector("button[type=submit]").recaptchaID = recaptchaID;
[601] Fix | Delete
} catch (error) {}
[602] Fix | Delete
});
[603] Fix | Delete
wpformsDispatchEvent(document, "wpformsRecaptchaLoaded", true);
[604] Fix | Delete
} );
[605] Fix | Delete
var wpformsRecaptchaCallback = function (el) {
[606] Fix | Delete
var $form = el.closest("form");
[607] Fix | Delete
if (typeof wpforms.formSubmit === "function") {
[608] Fix | Delete
wpforms.formSubmit($form);
[609] Fix | Delete
} else {
[610] Fix | Delete
$form.querySelector("button[type=submit]").recaptchaID = false;
[611] Fix | Delete
$form.submit();
[612] Fix | Delete
}
[613] Fix | Delete
};
[614] Fix | Delete
var wpformsRecaptchaErrorCallback = function (el) {
[615] Fix | Delete
var $form = el.closest("form");
[616] Fix | Delete
$form.querySelector("button[type=submit]").dataset.captchaInvalid = true;
[617] Fix | Delete
};
[618] Fix | Delete
';
[619] Fix | Delete
} else {
[620] Fix | Delete
$data = $dispatch;
[621] Fix | Delete
$data .= $callback;
[622] Fix | Delete
[623] Fix | Delete
$data .= /** @lang JavaScript */
[624] Fix | Delete
'var wpformsRecaptchaLoad = function () {
[625] Fix | Delete
Array.prototype.forEach.call(document.querySelectorAll(".g-recaptcha"), function (el) {
[626] Fix | Delete
try {
[627] Fix | Delete
var recaptchaID = grecaptcha.render(el, {
[628] Fix | Delete
callback: function () {
[629] Fix | Delete
wpformsRecaptchaCallback(el);
[630] Fix | Delete
}
[631] Fix | Delete
});
[632] Fix | Delete
el.setAttribute("data-recaptcha-id", recaptchaID);
[633] Fix | Delete
} catch (error) {}
[634] Fix | Delete
});
[635] Fix | Delete
wpformsDispatchEvent(document, "wpformsRecaptchaLoaded", true);
[636] Fix | Delete
};
[637] Fix | Delete
';
[638] Fix | Delete
}
[639] Fix | Delete
[640] Fix | Delete
return $data;
[641] Fix | Delete
}
[642] Fix | Delete
[643] Fix | Delete
/**
[644] Fix | Delete
* Cloudflare Turnstile captcha requires defer attribute.
[645] Fix | Delete
*
[646] Fix | Delete
* @since 1.8.1
[647] Fix | Delete
*
[648] Fix | Delete
* @param string $tag HTML for the script tag.
[649] Fix | Delete
* @param string $handle Handle of script.
[650] Fix | Delete
* @param string $src Src of script.
[651] Fix | Delete
*
[652] Fix | Delete
* @return string
[653] Fix | Delete
*/
[654] Fix | Delete
public function set_defer_attribute( $tag, $handle, $src ) {
[655] Fix | Delete
[656] Fix | Delete
$captcha_settings = wpforms_get_captcha_settings();
[657] Fix | Delete
[658] Fix | Delete
if ( $captcha_settings['provider'] !== 'turnstile' ) {
[659] Fix | Delete
return $tag;
[660] Fix | Delete
}
[661] Fix | Delete
[662] Fix | Delete
if ( $handle !== 'wpforms-recaptcha' ) {
[663] Fix | Delete
return $tag;
[664] Fix | Delete
}
[665] Fix | Delete
[666] Fix | Delete
return str_replace( ' src', ' defer src', $tag );
[667] Fix | Delete
}
[668] Fix | Delete
}
[669] Fix | Delete
[670] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function