Contact Form 7 anti spam upgrades
All checks were successful
Generate Build Info / build-info (push) Successful in 2s
All checks were successful
Generate Build Info / build-info (push) Successful in 2s
This commit is contained in:
46
dapper.php
46
dapper.php
@@ -1208,26 +1208,44 @@ if ( class_exists( 'WPCF7' ) ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. NEW: Visible checkbox — use reliable append method
|
// 2. NEW: Visible checkbox — use reliable append method
|
||||||
add_filter( 'wpcf7_form_elements', 'dapper_cf7_append_human_checkbox', 30 ); // Higher priority = later
|
add_filter( 'wpcf7_form_elements', 'dapper_cf7_append_human_checkbox', 100 ); // Higher priority = later
|
||||||
function dapper_cf7_append_human_checkbox( $form ) {
|
function dapper_cf7_append_human_checkbox( $form ) {
|
||||||
if ( get_option( 'dapper_enable_cf7_human_checkbox', 'on' ) !== 'on' ) {
|
if ( get_option( 'dapper_enable_cf7_human_checkbox', 'on' ) !== 'on' ) {
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debug: Confirm filter is firing (now using your helper)
|
||||||
|
dapper_debug_log( 'CF7 checkbox filter FIRED - form length before insert: ' . strlen( $form ) );
|
||||||
|
|
||||||
$unique = uniqid();
|
$unique = uniqid();
|
||||||
$checkbox_html = '
|
$checkbox_html = '
|
||||||
<div class="dapper-cf7-human-check" style="margin:1.8em 0 1.2em; padding:1em; background:#f8f9fa; border:1px solid #ccd0d4; border-radius:4px; text-align:center;">
|
<div class="dapper-cf7-human-check" style="margin: 1.5em 0; padding: 1em; background: #f8f9fa; border: 1px solid #ccd0d4; border-radius: 4px; text-align: center;">
|
||||||
<label style="font-size:1.1em; cursor:pointer; user-select:none; display:inline-flex; align-items:center; gap:0.8em;">
|
<label style="font-size: 1.1em; cursor: pointer; user-select: none;">
|
||||||
<input type="checkbox" name="dapper_cf7_human_confirm" value="1" required style="transform:scale(1.5);">
|
<input type="checkbox" name="dapper_cf7_human_confirm" id="dapper_cf7_human_confirm_' . $unique . '" value="1" required style="transform: scale(1.4); margin-right: 0.8em; vertical-align: middle;">
|
||||||
I am human / not a robot
|
I am human / not a robot
|
||||||
</label>
|
</label>
|
||||||
<input type="hidden" name="dapper_cf7_human_token" value="">
|
<input type="hidden" name="dapper_cf7_human_token" id="dapper_cf7_human_token_' . $unique . '" value="">
|
||||||
<input type="hidden" name="dapper_cf7_human_time" value="' . time() . '">
|
<input type="hidden" name="dapper_cf7_human_time" value="' . time() . '">
|
||||||
<p style="margin:0.6em 0 0; font-size:0.9em; color:#555;">Quick check to stop spam — thank you!</p>
|
<p style="margin: 0.6em 0 0; font-size: 0.9em; color: #555;">Quick check to help stop spam. Thanks!</p>
|
||||||
</div>';
|
</div>';
|
||||||
|
|
||||||
// Append right before the closing </form> — most reliable
|
// 1. Try after the response output div (common in widgets/Flatsome)
|
||||||
return str_replace( '</form>', $checkbox_html . '</form>', $form );
|
$form = preg_replace( '/(<div class="wpcf7-response-output"[^>]*>.*?<\/div>)/is', '$1' . $checkbox_html, $form, 1 );
|
||||||
|
|
||||||
|
// 2. If not found, insert before </form>
|
||||||
|
if ( strpos( $form, $checkbox_html ) === false ) {
|
||||||
|
$form = str_replace( '</form>', $checkbox_html . '</form>', $form );
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Ultimate fallback: just append to the end
|
||||||
|
if ( strpos( $form, $checkbox_html ) === false ) {
|
||||||
|
$form .= $checkbox_html;
|
||||||
|
dapper_debug_log( 'CF7 checkbox FALLBACK append used (no </form> or response div match)' );
|
||||||
|
}
|
||||||
|
|
||||||
|
dapper_debug_log( 'CF7 checkbox filter COMPLETE - insertion attempted' );
|
||||||
|
|
||||||
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tiny JS to set token + disable submit until checked
|
// Tiny JS to set token + disable submit until checked
|
||||||
|
|||||||
Reference in New Issue
Block a user