PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.8.1
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.8.1
5.8.0 5.8.1 5.7.0 5.6.2 5.6.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 All 41 releases
double-opt-in / OnActivation.php

OnActivation.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 5.8.1, at OnActivation.php

215 lines 5.7 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
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 consent_text TEXT,
51 consent_field varchar(64) DEFAULT '',
52 reminder_sent_at varchar(255) DEFAULT '',
53 mail_reminder LONGTEXT,
54 mail_status varchar(20) NOT NULL DEFAULT '',
55 mail_error varchar(255) NOT NULL DEFAULT '',
56 mail_status_at varchar(19) NOT NULL DEFAULT '',
57 PRIMARY KEY (id)
58 )";
59
60 dbDelta( $sql );
61
62 $logger->info( 'Database table created or updated', [
63 'plugin' => 'double-opt-in',
64 'table_name' => $wpTableName,
65 'class' => __CLASS__ ?? null,
66 'method' => __FUNCTION__,
67 ] );
68 }
69
70
71 /**
72 * Create the table for the categories
73 *
74 * @return void
75 */
76 function createTableOptinCategories() {
77 global $wpdb;
78
79 $logger = Logger::getInstance();
80
81 $tableName = 'f12_cf7_doubleoptin_categories';
82 $wpTableName = $wpdb->prefix . $tableName;
83
84 $logger->info( 'Creating database table', [
85 'plugin' => 'double-opt-in',
86 'table_name' => $wpTableName,
87 'class' => __CLASS__ ?? null,
88 'method' => __FUNCTION__,
89 ] );
90
91 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
92
93 $sql = "CREATE TABLE " . $wpTableName . " (
94 id int(11) NOT NULL auto_increment,
95 name varchar(255),
96 createtime varchar(255) DEFAULT '',
97 updatetime varchar(255) DEFAULT '',
98 PRIMARY KEY (id)
99 )";
100
101 dbDelta( $sql );
102
103 $logger->info( 'Database table created or updated', [
104 'plugin' => 'double-opt-in',
105 'table_name' => $wpTableName,
106 'class' => __CLASS__ ?? null,
107 'method' => __FUNCTION__,
108 ] );
109 }
110
111
112 /**
113 * On Activation create the custom table to store the required information
114 * for the double opt in system.
115 */
116 function onActivation( $network_wide = false ) {
117 $logger = Logger::getInstance();
118
119 $logger->info( 'Plugin activation started', [
120 'plugin' => 'double-opt-in',
121 'network_wide' => $network_wide,
122 'class' => __CLASS__ ?? null,
123 'method' => __FUNCTION__,
124 ] );
125
126 if ( is_multisite() && $network_wide ) {
127 $sites = get_sites( [ 'fields' => 'ids', 'number' => 0 ] );
128 foreach ( $sites as $site_id ) {
129 switch_to_blog( $site_id );
130 createTableOptin();
131 createTableOptinCategories();
132 createTableAuditLog();
133 \Forge12\DoubleOptIn\Repository\FollowUpSchema::install();
134 restore_current_blog();
135 }
136 } else {
137 createTableOptin();
138 createTableOptinCategories();
139 createTableAuditLog();
140 \Forge12\DoubleOptIn\Repository\FollowUpSchema::install();
141 }
142
143 // Open the setup wizard once after a single-site activation.
144 if ( class_exists( '\Forge12\DoubleOptIn\Setup\SetupRedirect' ) ) {
145 \Forge12\DoubleOptIn\Setup\SetupRedirect::onActivation( (bool) $network_wide );
146 }
147
148 $logger->info( 'Plugin activation completed', [
149 'plugin' => 'double-opt-in',
150 'network_wide' => $network_wide,
151 'class' => __CLASS__ ?? null,
152 'method' => __FUNCTION__,
153 ] );
154 }
155
156 /**
157 * Create the table for the audit log.
158 *
159 * @since 4.2.0
160 * @return void
161 */
162 function createTableAuditLog() {
163 global $wpdb;
164
165 $logger = Logger::getInstance();
166
167 $tableName = 'f12_cf7_doubleoptin_audit_log';
168 $wpTableName = $wpdb->prefix . $tableName;
169
170 $logger->info( 'Creating audit log table', [
171 'plugin' => 'double-opt-in',
172 'table_name' => $wpTableName,
173 'method' => __FUNCTION__,
174 ] );
175
176 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
177
178 $sql = "CREATE TABLE " . $wpTableName . " (
179 id bigint(20) unsigned NOT NULL auto_increment,
180 event_type varchar(50) NOT NULL,
181 severity varchar(20) NOT NULL DEFAULT 'info',
182 message text NOT NULL,
183 user_id bigint(20) unsigned DEFAULT NULL,
184 details longtext DEFAULT NULL,
185 created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
186 PRIMARY KEY (id),
187 KEY idx_type (event_type),
188 KEY idx_severity (severity),
189 KEY idx_created (created_at)
190 )";
191
192 dbDelta( $sql );
193
194 $logger->info( 'Audit log table created or updated', [
195 'plugin' => 'double-opt-in',
196 'table_name' => $wpTableName,
197 'method' => __FUNCTION__,
198 ] );
199 }
200
201 register_activation_hook( plugin_dir_path(__FILE__).'CF7DoubleOptIn.class.php', '\forge12\contactform7\CF7DoubleOptIn\onActivation' );
202
203 add_action( 'wp_initialize_site', function ( $new_site ) {
204 if ( ! is_plugin_active_for_network(
205 plugin_basename( __DIR__ . '/CF7DoubleOptIn.class.php' )
206 ) ) {
207 return;
208 }
209 switch_to_blog( $new_site->blog_id );
210 createTableOptin();
211 createTableOptinCategories();
212 createTableAuditLog();
213 \Forge12\DoubleOptIn\Repository\FollowUpSchema::install();
214 restore_current_blog();
215 }, 900 );