| 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 |
} |