Created
June 1, 2018 14:46
-
-
Save fulippo/b469817c1fc22e9e5d31c627f0931484 to your computer and use it in GitHub Desktop.
Fix Gravity Forms Captcha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This action should be inside add_actions | |
/** | |
* Remove Gravityforms captcha action | |
* This is a fix to prevent interferences from commonLib.js | |
*/ | |
add_action('get_footer', function(){ | |
global $wp_filter; | |
foreach($wp_filter['wp_footer']->callbacks as $priority => $hooks){ | |
foreach($hooks as $k => $hook){ | |
if(is_array($hook['function']) | |
&& count($hook['function']) == 2 && is_a($hook['function'][0], 'GF_Field_CAPTCHA') | |
&& $hook['function'][1] == 'ensure_recaptcha_js'){ | |
unset($wp_filter['wp_footer']->callbacks[$priority][$k]); | |
} | |
} | |
} | |
add_action('wp_footer', [$this, 'fix_gravityforms_recaptcha_js']); | |
}); | |
/** | |
* Re-add the same logic from gravityforms with an | |
* additional check | |
*/ | |
public function fix_gravityforms_recaptcha_js() { | |
?> | |
<script type="text/javascript"> | |
var gfRecaptchaPoller = setInterval( function() { | |
if( typeof renderRecaptcha === 'undefined' || ! window.grecaptcha || ! window.grecaptcha.render ) { | |
return; | |
} | |
renderRecaptcha(); | |
clearInterval( gfRecaptchaPoller ); | |
}, 100 ); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If this is NOT working for anyone, we had to delay action to
wp_footer
. On one machine the above worked perfectly. On another we had to useadd_action('wp_footer', function () { .... })
in order to get this work.Unfortunately I do not have an explanation as to why, but if that tip helps anyone, i'll be happy.