/*
Theme Name: Enfold Child
Description: A <a href='http://codex.wordpress.org/Child_Themes'>Child Theme</a> for the Enfold Wordpress Theme. If you plan to do a lot of file modifications we recommend to use this Theme instead of the original Theme. Updating will be much easier then.
Version: 1.0
Author: Kriesi
Author URI: http://www.kriesi.at
Template: enfold
*/



/*Add your own styles here:*/
<?php
// In der functions.php deines Enfold Child Themes

// Mindest-Zeit bis Formular abgeschickt werden darf (Sekunden)
define('CF7_MIN_SUBMIT_TIME', 4);

add_filter('wpcf7_form_hidden_fields', function ($fields) {
    $fields['form_load_time'] = time();
    return $fields;
});

add_filter('wpcf7_spam', function ($spam) {
    if (isset($_POST['form_load_time'])) {
        $elapsed = time() - intval($_POST['form_load_time']);
        if ($elapsed < CF7_MIN_SUBMIT_TIME) {
            $spam = true; // zu schnell -> vermutlich Bot
        }
    }
    return $spam;
});

// Optional: Rate-Limiting pro IP (max. 3 Anfragen/Stunde)
add_filter('wpcf7_spam', function ($spam) {
    $ip = $_SERVER['REMOTE_ADDR'] ?? '';
    if (!$ip) return $spam;

    $key = 'cf7_rl_' . md5($ip);
    $count = (int) get_transient($key);

    if ($count >= 3) {
        $spam = true;
    } else {
        set_transient($key, $count + 1, HOUR_IN_SECONDS);
    }
    return $spam;
});