| |
| <?php
|
|
|
|
|
|
|
|
|
|
|
| function bms_page_has_form() {
|
| if ( ! is_singular() ) return false;
|
|
|
| $post_id = get_queried_object_id();
|
| if ( ! $post_id ) return false;
|
|
|
|
|
| $content = (string) get_post_field( 'post_content', $post_id );
|
|
|
|
|
| if ( has_shortcode( $content, 'forminator_form' ) ) return true;
|
| if ( has_shortcode( $content, 'contact-form-7' ) ) return true;
|
| if ( has_shortcode( $content, 'elementor-template' ) ) return true;
|
|
|
|
|
| if ( function_exists( 'has_block' ) ) {
|
| if ( has_block( 'forminator/forminator-form', $content ) ) return true;
|
| if ( has_block( 'contact-form-7/contact-form-selector', $content ) ) return true;
|
| }
|
|
|
|
|
| foreach ( array( 'elementor-widget-form', 'wpcf7-form', 'forminator-custom-form' ) as $needle ) {
|
| if ( stripos( $content, $needle ) !== false ) return true;
|
| }
|
|
|
| return false;
|
| }
|
|
|
|
|
| add_action( 'wp_print_scripts', function () {
|
| if ( is_admin() || bms_page_has_form() ) return;
|
|
|
| $patterns = array(
|
| 'forminator',
|
| 'contact-form-7',
|
| 'elementor-pro',
|
| 'recaptcha', 'grecaptcha', 'gstatic/recaptcha', 'google.com/recaptcha'
|
| );
|
|
|
| $wp_scripts = wp_scripts();
|
| if ( empty( $wp_scripts->queue ) ) return;
|
|
|
| foreach ( (array) $wp_scripts->queue as $handle ) {
|
| if ( empty( $wp_scripts->registered[ $handle ] ) ) continue;
|
| $src = (string) $wp_scripts->registered[ $handle ]->src;
|
| foreach ( $patterns as $p ) {
|
| if ( $src && stripos( $src, $p ) !== false ) {
|
| wp_dequeue_script( $handle );
|
| wp_deregister_script( $handle );
|
| break;
|
| }
|
| }
|
| }
|
| }, 999 );
|
|
|
|
|
| add_action( 'wp_print_styles', function () {
|
| if ( is_admin() || bms_page_has_form() ) return;
|
|
|
| $patterns = array( 'forminator', 'contact-form-7', 'elementor-pro' );
|
|
|
| $wp_styles = wp_styles();
|
| if ( empty( $wp_styles->queue ) ) return;
|
|
|
| foreach ( (array) $wp_styles->queue as $handle ) {
|
| if ( empty( $wp_styles->registered[ $handle ] ) ) continue;
|
| $src = (string) $wp_styles->registered[ $handle ]->src;
|
| foreach ( $patterns as $p ) {
|
| if ( $src && stripos( $src, $p ) !== false ) {
|
| wp_dequeue_style( $handle );
|
| break;
|
| }
|
| }
|
| }
|
| }, 999 );
|
|
|
|
|
| add_action( 'wp_footer', function () {
|
| if ( ! bms_page_has_form() ) return;
|
|
|
| $js = <<<JS
|
| <script>
|
| (function () {
|
| var loaded=false;
|
| function loadRecaptcha(){
|
| if(loaded) return; loaded=true;
|
| var s=document.createElement('script');
|
| s.src='https://www.google.com/recaptcha/api.js?render=explicit';
|
| s.async=true; s.defer=true;
|
| document.head.appendChild(s);
|
| }
|
| ['focus','mousedown','touchstart','keydown','scroll'].forEach(function(evt){
|
| window.addEventListener(evt,function once(){
|
| window.removeEventListener(evt,once,{passive:true});
|
| loadRecaptcha();
|
| },{once:true,passive:true});
|
| });
|
| setTimeout(loadRecaptcha,6000);
|
| })();
|
| </script>
|
| JS;
|
| echo $js;
|
| }, 99 );
|
|
|
|
|
| |
| |
Comments