Working in popup assumes another initialization sequence, which varies significantly depending on the implementation.
Do you mean problems in the popup “Оставить заявку”? (You forgot to attach the screenshot).
Was it created via wpb popup for contact form 7 ?
This reply was modified 8 months, 2 weeks ago by kaggdesign .
Yes, it’s WPB Popup for Contact Form 7. All contact forms on the website are created using this plugin, and hCaptcha doesn’t work in any of them.
The WPB Popup plugin is too small. We cannot add support for it in our plugin.
On you site, you can use the following snippet.
add_filter( 'hcap_print_hcaptcha_scripts', static function (): bool { if ( ! is_page( 'wpb-popup' ) || ! doing_action( 'wp_print_footer_scripts' ) ) { return false; } $script = <<<HTML <script> jQuery( document ).on( 'ajaxComplete', function( event, xhr, settings ) { const params = new URLSearchParams( settings.data ); if ( params.get( 'action' ) !== 'wpb_pcf_fire_contact_form' ) { return; } window.hCaptchaBindEvents(); } ); </script> HTML; echo $script; return true; } ); add_action( 'hcap_protect_form', static function ( $value, array $source, $form_id ): bool { $value = (bool) $value; if ( $source === [ 'contact-form-7/wp-contact-form-7.php' ] ) { hcaptcha()->settings()->set( 'honeypot', [ '' ] ); hcaptcha()->settings()->set( 'set_min_submit_time', [ '' ] ); } return $value; }, 20, 3 );
Instead of is_page( 'wpb-popup' ) please use ID of your homepage: is_page( 754 ).
Kindly let me know if the above snippet works for you.
This reply was modified 8 months, 2 weeks ago by kaggdesign .
Thank you so much for your code! It fixed everything. I only added display on all pages, and now it works perfectly. You are the best! 💙
add_filter( 'hcap_print_hcaptcha_scripts', static function (): bool { if ( ! doing_action( 'wp_print_footer_scripts' ) ) { return false; } $script = <<<HTML <script> jQuery(document).on('ajaxComplete', function(event, xhr, settings) { const params = new URLSearchParams(settings.data); if (params.get('action') !== 'wpb_pcf_fire_contact_form') { return; } if (typeof window.hCaptchaBindEvents === 'function') { window.hCaptchaBindEvents(); return; } if (typeof hcaptcha !== 'undefined' && typeof hcaptcha.render === 'function') { jQuery('.h-captcha').each(function() { const widgetId = this.getAttribute('data-widget-id'); if (widgetId) { hcaptcha.reset(widgetId); } else { hcaptcha.render(this); } }); } }); </script> HTML; echo $script; return true; } );
Good to know that it helped.
Thank you for your kind review!
This reply was modified 8 months, 2 weeks ago by kaggdesign .