Skip to content

Commit 26e6f4e

Browse files
committed
checks if the mail was sent in a "period of grace"
1 parent 1c7a6ec commit 26e6f4e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

core/CF7_AntiSpam_Filters.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ public function cf7a_spam_filter( $spam ) {
248248
/* Get plugin options */
249249
$options = get_option( 'cf7a_options', array() );
250250

251+
/* Check the period of grace and, if it is expired, reset the error count */
252+
if ( isset( $options['last_update_data']['errors'] ) ) {
253+
if ( time() - $options['last_update_data']['errors']['timestamp'] > $options['cf7a_period_of_grace'] ) {
254+
$options['last_update_data']['errors'] = array();
255+
}
256+
// then save the updated options to the database
257+
update_option( 'cf7a_options', $options );
258+
}
259+
251260
/* Get basic submission details */
252261
$mail_tags = $contact_form->scan_form_tags();
253262
$email_tag = sanitize_title( cf7a_get_mail_meta( $contact_form->pref( 'flamingo_email' ) ) );
@@ -959,4 +968,23 @@ public function filter_b8_bayesian( $data ) {
959968
}
960969
return $data;
961970
}
971+
972+
/**
973+
* Sends an email to the admin, warning them to clear the cache.
974+
* @param array $update_data the array of data to be sent to the admin
975+
* @return void
976+
*/
977+
private function send_cache_warning_email( $update_data ): void {
978+
$tools = new CF7_AntiSpam_Admin_Tools();
979+
$recipient = get_option( 'admin_email' );
980+
$body = sprintf(
981+
"Hello Admin,\n\nWe detected 5 users trying to submit forms with the old version (%s) instead of the new one (%s).\n\nThis usually means your website cache (or CDN) hasn't been cleared after the last update.\n\nPlease purge your site cache immediately to prevent legitimate users from being flagged as spam.\n\nTime of update: %s",
982+
$update_data['old_version'],
983+
$update_data['new_version'],
984+
gmdate( 'Y-m-d H:i:s', $update_data['time'] )
985+
);
986+
$subject = 'CF7 AntiSpam - Cache Warning Alert';
987+
988+
$tools->send_email_to_admin( $subject, $recipient, $body, $recipient );
989+
}
962990
}

0 commit comments

Comments
 (0)