PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 3.0.3
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v3.0.3
5.6.1 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 All 36 releases
double-opt-in / core / CleanUp.class.php

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

102 lines 3.4 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 * Use force to delete confirmed opt-ins in the database settings.
64 */
65 public function removeUnconfirmedOptins($force = false)
66 {
67 $Settings = CF7DoubleOptIn::getInstance()->getSettings();
68
69 if (($Settings['delete_unconfirmed'] == 0 || !is_numeric($Settings['delete_unconfirmed'])) && !$force) {
70 return;
71 }
72
73 $period = $Settings['delete_unconfirmed_period'];
74
75 $timestamp = strtotime("- " . (int)$Settings['delete_unconfirmed'] . " ".$period, time());
76
77 $this->removeOlderThan($timestamp, 0);
78 }
79
80 /**
81 * Clear all confimred database entries if the period selected
82 * is reached.
83 *
84 * Use force to delete confirmed opt-ins in the database settings.
85 */
86 public function removeConfirmedOptins($force = false)
87 {
88 $Settings = CF7DoubleOptIn::getInstance()->getSettings();
89
90 if (($Settings['delete'] == 0 || !is_numeric($Settings['delete'])) && !$force) {
91 return;
92 }
93
94 $period = $Settings['delete_period'];
95
96 $timestamp = strtotime("- " . (int)$Settings['delete'] . " ".$period, time());
97
98 $this->removeOlderThan($timestamp, 1);
99 }
100
101 }
102 }