| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn; |
| 4 |
|
| 5 |
use Forge12\Shared\Logger; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Create the table to store the opt ins. |
| 13 |
* |
| 14 |
* @return void |
| 15 |
*/ |
| 16 |
function createTableOptIn() { |
| 17 |
global $wpdb; |
| 18 |
|
| 19 |
$logger = Logger::getInstance(); |
| 20 |
|
| 21 |
$tableName = 'f12_cf7_doubleoptin'; |
| 22 |
$wpTableName = $wpdb->prefix . $tableName; |
| 23 |
|
| 24 |
$logger->info( 'Creating database table', [ |
| 25 |
'plugin' => 'double-opt-in', |
| 26 |
'table_name' => $wpTableName, |
| 27 |
'class' => __CLASS__ ?? null, |
| 28 |
'method' => __FUNCTION__, |
| 29 |
] ); |
| 30 |
|
| 31 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 32 |
|
| 33 |
$sql = "CREATE TABLE " . $wpTableName . " ( |
| 34 |
id int(11) NOT NULL auto_increment, |
| 35 |
cf_form_id int(11) NOT NULL, |
| 36 |
doubleoptin int(2), |
| 37 |
content LONGTEXT, |
| 38 |
files LONGTEXT, |
| 39 |
hash VARCHAR(255), |
| 40 |
ipaddr_register varchar(255) NOT NULL DEFAULT '', |
| 41 |
ipaddr_confirmation varchar(255) NOT NULL DEFAULT '', |
| 42 |
ipaddr_optout varchar(255) NOT NULL DEFAULT '', |
| 43 |
createtime varchar(255) DEFAULT '', |
| 44 |
updatetime varchar(255) DEFAULT '', |
| 45 |
optouttime varchar(255) DEFAULT '', |
| 46 |
category int(11), |
| 47 |
email varchar(255), |
| 48 |
form LONGTEXT, |
| 49 |
mail_optin LONGTEXT, |
| 50 |
PRIMARY KEY (id) |
| 51 |
)"; |
| 52 |
|
| 53 |
dbDelta( $sql ); |
| 54 |
|
| 55 |
$logger->info( 'Database table created or updated', [ |
| 56 |
'plugin' => 'double-opt-in', |
| 57 |
'table_name' => $wpTableName, |
| 58 |
'class' => __CLASS__ ?? null, |
| 59 |
'method' => __FUNCTION__, |
| 60 |
] ); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
/** |
| 65 |
* Create the table for the categories |
| 66 |
* |
| 67 |
* @return void |
| 68 |
*/ |
| 69 |
function createTableOptinCategories() { |
| 70 |
global $wpdb; |
| 71 |
|
| 72 |
$logger = Logger::getInstance(); |
| 73 |
|
| 74 |
$tableName = 'f12_cf7_doubleoptin_categories'; |
| 75 |
$wpTableName = $wpdb->prefix . $tableName; |
| 76 |
|
| 77 |
$logger->info( 'Creating database table', [ |
| 78 |
'plugin' => 'double-opt-in', |
| 79 |
'table_name' => $wpTableName, |
| 80 |
'class' => __CLASS__ ?? null, |
| 81 |
'method' => __FUNCTION__, |
| 82 |
] ); |
| 83 |
|
| 84 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 85 |
|
| 86 |
$sql = "CREATE TABLE " . $wpTableName . " ( |
| 87 |
id int(11) NOT NULL auto_increment, |
| 88 |
name varchar(255), |
| 89 |
createtime varchar(255) DEFAULT '', |
| 90 |
updatetime varchar(255) DEFAULT '', |
| 91 |
PRIMARY KEY (id) |
| 92 |
)"; |
| 93 |
|
| 94 |
dbDelta( $sql ); |
| 95 |
|
| 96 |
$logger->info( 'Database table created or updated', [ |
| 97 |
'plugin' => 'double-opt-in', |
| 98 |
'table_name' => $wpTableName, |
| 99 |
'class' => __CLASS__ ?? null, |
| 100 |
'method' => __FUNCTION__, |
| 101 |
] ); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
/** |
| 106 |
* On Activation create the custom table to store the required information |
| 107 |
* for the double opt in system. |
| 108 |
*/ |
| 109 |
function onActivation() { |
| 110 |
$logger = Logger::getInstance(); |
| 111 |
|
| 112 |
$logger->info( 'Plugin activation started', [ |
| 113 |
'plugin' => 'double-opt-in', |
| 114 |
'class' => __CLASS__ ?? null, |
| 115 |
'method' => __FUNCTION__, |
| 116 |
] ); |
| 117 |
|
| 118 |
createTableOptin(); |
| 119 |
$logger->debug( 'createTableOptin executed', [ |
| 120 |
'plugin' => 'double-opt-in', |
| 121 |
] ); |
| 122 |
|
| 123 |
createTableOptinCategories(); |
| 124 |
$logger->debug( 'createTableOptinCategories executed', [ |
| 125 |
'plugin' => 'double-opt-in', |
| 126 |
] ); |
| 127 |
|
| 128 |
$logger->info( 'Plugin activation completed', [ |
| 129 |
'plugin' => 'double-opt-in', |
| 130 |
'class' => __CLASS__ ?? null, |
| 131 |
'method' => __FUNCTION__, |
| 132 |
] ); |
| 133 |
} |
| 134 |
|
| 135 |
register_activation_hook( plugin_dir_path(__FILE__).'CF7DoubleOptIn.class.php', '\forge12\contactform7\CF7DoubleOptIn\onActivation' ); |