PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 2.12
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v2.12
5.6.0 5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 3.0.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.51 3.0.60 3.0.61 3.0.62 3.0.70 3.0.71 3.0.72 All 35 releases
double-opt-in / core / CleanUp.class.php

CleanUp.class.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 2.12, at core/CleanUp.class.php

98 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace forge12\contactform7\CF7DoubleOptIn {
4 if(!defined('ABSPATH')){
5 exit;
6 }
7 /**
8 * This class will handle the clean up of the database
9 * as defined by the user settings.
10 */
11 class CleanUp
12 {
13 public function __construct()
14 {
15 add_action('dailyOptinClear', array($this, 'removeUnconfirmedOptins'));
16 add_action('dailyOptinClear', array($this, 'removeConfirmedOptins'));
17 }
18
19 /**
20 * Delete the given hash entry
21 */
22 public function deleteByHash($hash){
23 if(current_user_can('manage_options')){
24 global $wpdb;
25 $tableName = 'f12_cf7_doubleoptin';
26 $wpTableName = $wpdb->prefix . $tableName;
27
28 return $wpdb->query('DELETE FROM ' . $wpTableName . ' WHERE hash="' . $hash . '"');
29 }
30 return false;
31 }
32
33 /**
34 * Delete all Rows from the Database which are older than the given timestamp and where the optin value matches as defined.
35 * @param $timestamp
36 * @param int $optin
37 */
38 private function removeOlderThan($timestamp, $optin = 0)
39 {
40 global $wpdb;
41 $tableName = 'f12_cf7_doubleoptin';
42 $wpTableName = $wpdb->prefix . $tableName;
43
44 //$sql = 'DELETE FROM ' . $wpTableName . ' WHERE createtime < "' . $timestamp . '" AND doubleoptin="' . $optin . '"';
45 $wpdb->query('DELETE FROM ' . $wpTableName . ' WHERE createtime < "' . $timestamp . '" AND doubleoptin="' . $optin . '"');
46 }
47
48 /**
49 * Delete all DOI entries
50 */
51 public function reset(){
52 global $wpdb;
53 $tableName = 'f12_cf7_doubleoptin';
54 $wpTableName = $wpdb->prefix . $tableName;
55
56 $wpdb->query('DELETE FROM ' . $wpTableName);
57 }
58
59 /**
60 * Clear all unconfirmed database entries if the period selected
61 * is reached.
62 */
63 public function removeUnconfirmedOptins()
64 {
65 $Settings = CF7DoubleOptIn::getInstance()->getSettings();
66
67 if ($Settings['delete_unconfirmed'] == 0 || !is_numeric($Settings['delete_unconfirmed'])) {
68 return;
69 }
70
71 $period = $Settings['delete_unconfirmed_period'];
72
73 $timestamp = strtotime("- " . (int)$Settings['delete_unconfirmed'] . " ".$period, time());
74
75 $this->removeOlderThan($timestamp, 0);
76 }
77
78 /**
79 * Clear all confimred database entries if the period selected
80 * is reached.
81 */
82 public function removeConfirmedOptins()
83 {
84 $Settings = CF7DoubleOptIn::getInstance()->getSettings();
85
86 if ($Settings['delete'] == 0 || !is_numeric($Settings['delete'])) {
87 return;
88 }
89
90 $period = $Settings['delete_period'];
91
92 $timestamp = strtotime("- " . (int)$Settings['delete'] . " ".$period, time());
93
94 $this->removeOlderThan($timestamp, 1);
95 }
96
97 }
98 }