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!
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() { Enable "I'm human" checkbox on all CF7 forms > -