Better CF7 toggle protection
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:
30
dapper.php
30
dapper.php
@@ -1144,12 +1144,16 @@ add_action( 'plugins_loaded', 'dapper_woo_conditional_load' ); // Late hook –
|
||||
// ────────────────────────────────────────────────
|
||||
// Contact Form 7 protection (always loaded if CF7 exists)
|
||||
// ────────────────────────────────────────────────
|
||||
if ( class_exists( 'WPCF7' ) ) {
|
||||
if ( get_option('dapper_enable_cf7_protection', 'on') === 'on' ) {
|
||||
|
||||
// Add hidden fields to Contact Form 7 forms
|
||||
add_filter('wpcf7_form_hidden_fields', 'dapper_cf7_hidden_fields');
|
||||
function dapper_cf7_hidden_fields($fields) {
|
||||
|
||||
if ( ! dapper_cf7_enabled() ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$fields['dapper_ts'] = time();
|
||||
$fields['dapper_token'] = '';
|
||||
|
||||
@@ -1158,6 +1162,10 @@ if ( class_exists( 'WPCF7' ) ) {
|
||||
|
||||
add_action('wp_footer', 'dapper_cf7_js_token', 100);
|
||||
function dapper_cf7_js_token() {
|
||||
if ( ! dapper_cf7_enabled() ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!defined('WPCF7_VERSION')) return;
|
||||
?>
|
||||
<script>
|
||||
@@ -1183,6 +1191,10 @@ if ( class_exists( 'WPCF7' ) ) {
|
||||
|
||||
add_filter('wpcf7_validate', 'dapper_cf7_validate', 20, 2);
|
||||
function dapper_cf7_validate($result, $tags) {
|
||||
if ( ! dapper_cf7_enabled() ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$submission = WPCF7_Submission::get_instance();
|
||||
if (!$submission) return $result;
|
||||
$data = $submission->get_posted_data();
|
||||
@@ -1243,6 +1255,10 @@ if ( class_exists( 'WPCF7' ) ) {
|
||||
add_filter('wpcf7_form_elements', 'dapper_cf7_honeypot');
|
||||
|
||||
function dapper_cf7_honeypot($form) {
|
||||
if ( ! dapper_cf7_enabled() ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$hp = '<span style="display:none;">
|
||||
<input type="text" name="dapper_hp" value="">
|
||||
</span>';
|
||||
@@ -1252,6 +1268,10 @@ if ( class_exists( 'WPCF7' ) ) {
|
||||
|
||||
|
||||
}
|
||||
function dapper_cf7_enabled() {
|
||||
return get_option('dapper_enable_cf7_protection', 'on') === 'on';
|
||||
}
|
||||
|
||||
|
||||
add_filter('rest_pre_dispatch', 'dapper_block_cf7_rest_spam', 10, 3);
|
||||
|
||||
@@ -1507,9 +1527,9 @@ function dapper_settings_page_content() {
|
||||
<?php checked(get_option('dapper_enable_paypal_human_check', 'on'), 'on'); ?>
|
||||
<?php echo $paypal_forced_off ? 'disabled' : ''; ?>>
|
||||
<h3>Contact Form 7 Protection</h3>
|
||||
<label for="dapper_enable_cf7_human_checkbox">Enable "I'm human" checkbox on all CF7 forms</label>
|
||||
<input type="checkbox" id="dapper_enable_cf7_human_checkbox" name="dapper_enable_cf7_human_checkbox"
|
||||
<?php checked( get_option( 'dapper_enable_cf7_human_checkbox', 'on' ), 'on' ); ?>>
|
||||
<label for="dapper_enable_cf7_protection">Enable Contact Form 7 anti spam blocking</label>
|
||||
<input type="checkbox" id="dapper_enable_cf7_protection" name="dapper_enable_cf7_protection"
|
||||
<?php checked( get_option( 'dapper_enable_cf7_protection', 'on' ), 'on' ); ?>>
|
||||
<?php
|
||||
submit_button();
|
||||
?>
|
||||
@@ -1751,7 +1771,7 @@ function dapper_register_settings() {
|
||||
register_setting('dapper-backup-group', 'dapper_backup_plugins');
|
||||
register_setting('dapper-backup-group', 'dapper_backup_include_media');
|
||||
register_setting('dapper-settings-group', 'dapper_enable_paypal_human_check');
|
||||
register_setting('dapper-settings-group', 'dapper_enable_cf7_human_checkbox');
|
||||
register_setting('dapper_settings_group', 'dapper_enable_cf7_protection');
|
||||
// Add other settings as needed
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user