From eef496ae31b24028a11114b751d8d7cdd3b6e838 Mon Sep 17 00:00:00 2001 From: carpentryplus25 Date: Tue, 10 Mar 2026 23:35:28 -0400 Subject: [PATCH] Better contact form 7 protection --- dapper.php | 64 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/dapper.php b/dapper.php index 139fcd4..0b429e2 100644 --- a/dapper.php +++ b/dapper.php @@ -1243,32 +1243,48 @@ if (class_exists('WPCF7')) { add_filter( 'wpcf7_form_elements', 'dapper_cf7_inject_human_checkbox', 20 ); function dapper_cf7_inject_human_checkbox( $form ) { - if ( get_option( 'dapper_enable_cf7_human_checkbox', 'on' ) !== 'on' ) { - return $form; - } - - $checkbox_html = ' -
- - - -

Quick check to help stop spam. Thanks!

-
'; - - // Insert just before the submit button / - $form = preg_replace( '/(]*type=["\']submit["\'][^>]*>.*?<\/button>)/is', $checkbox_html . '$1', $form ); - - // Fallback: if no + $form = preg_replace( + '/(<(?:input|button)[^>]*type=["\']submit["\'][^>]*>)/i', + $checkbox_html . '$1', + $form, + 1 // limit to first match + ); + + // 2. If that didn't work (rare), try before the wrapping

of submit + if ( strpos( $form, $checkbox_html ) === false ) { + $form = preg_replace( + '/(]*>[\s\S]*?(?:]*type=["\']submit["\'][^>]*>|<\/button>)[\s\S]*?<\/p>)/i', + $checkbox_html . '$1', + $form, + 1 + ); + } + + // 3. Ultimate fallback: just before + if ( strpos( $form, $checkbox_html ) === false ) { + $form = str_replace( '', $checkbox_html . '', $form ); + } + + return $form; +} + // 2. Very small JS — runs on every page that has CF7 (cheap) add_action( 'wp_footer', 'dapper_cf7_human_checkbox_js', 95 ); @@ -1540,7 +1556,7 @@ function dapper_settings_page_content() { > -