Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active February 21, 2021 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/4218d7fc819bd5943f69f9c55bc03e70 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/4218d7fc819bd5943f69f9c55bc03e70 to your computer and use it in GitHub Desktop.
[Forminator Pro] - Fix not showing captcha when Hustle with captcha is active.
<?php
/**
* Plugin Name: [Forminator Pro] - Fix not showing captcha when Hustle with captcha is active.
* Description: [Forminator Pro] - Fix not showing captcha when Hustle with captcha is active.
* Author: Thobk @ WPMUDEV
* Jira: SLS-1512
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
} elseif ( defined( 'WP_CLI' ) && WP_CLI ) {
return;
}
add_action( 'wp_footer', function(){
if ( defined('FORMINATOR_PRO') && class_exists( 'Forminator' ) ) {
?>
<script>
(function($){
$(function(){
function wpmudev_fm_regenerate_recaptcha(){
let _time = setInterval(function(){
let _forminator_captchas = $(document.body).find('.forminator-g-recaptcha');
if( _forminator_captchas.length && window.grecaptcha ){
_forminator_captchas.each(function(){
if( ! $(this).find('iframe').length ){
var form = $(this).closest('form');
if (form.length > 0) {
var forminatorFront = form.data('forminatorFront');
if (typeof forminatorFront !== 'undefined') {
if( _time ){
clearInterval(_time);
}
forminatorFront.renderCaptcha($(this)[0]);
}
}
}
});
if( _time ){
clearInterval(_time);
}
}else{
setTimeout(function(){
if( _time ){
clearInterval(_time);
}
},5000);
}
}, 500);
}
// fix with hustle.
if( $('.hustle-recaptcha').length ){
wpmudev_fm_regenerate_recaptcha();
}
// fix in ajax.
$(document).on('after.load.forminator', function(e, _form_id){
let _form = $('#forminator-module-'+ _form_id);
if( $('#forminator-module-'+ _form_id).find('.forminator-g-recaptcha').length ){
wpmudev_fm_regenerate_recaptcha();
}
});
});
})(window.jQuery)
</script>
<?php
}
}, 21 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment