PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.13.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.13.0
5.12.0 5.13.0 5.13.1 5.11.0 5.10.0 5.9.0 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 All 47 releases
double-opt-in / OnActivation.php

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

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