问题
I was wondering if you could help me solving this issue; I have created a email counter which increase the number +1 once the user send an email (this works great).
What I was trying to do is to reset the counter after 86400 seconds (one day) in a loop, so every day the counter will start counting from 0 the emails sent. I have tried many scripts but none of them works, this is the last sketch:
//Define the key to store in the database
define( 'CF7_COUNTER', 'cf7-counter' );
//Create the shortcode which will set the value for the DTX field
function cf7dtx_counter(){
$val = get_option( CF7_COUNTER, 0) + 1; //Increment the current count
return $val;
}
add_shortcode('CF7_counter', 'cf7dtx_counter');
function setInter($f, $milliseconds) {
$seconds=(int)$milliseconds/1000;
while(true) {
$f();
sleep($seconds);
}
}
//Action performed when the mail is actually sent by CF7
function cf7dtx_increment_mail_counter(){
$val = get_option( CF7_COUNTER, 0) + 1; //Increment the current count
update_option(CF7_COUNTER, $val); //Update the settings with the new count
setInter(function(){$val=0; update_option(CF7_COUNTER,$val); cf7dtx_increment_mail_counter();},30000); //Reset the counter after 60 seconds
}
add_action('wpcf7_mail_sent', 'cf7dtx_increment_mail_counter');
来源:https://stackoverflow.com/questions/62122889/create-a-mail-counter-for-contact-form-7