PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.7.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.7.0
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 3.0.60 3.0.61 All 39 releases
double-opt-in / OnActivation.php

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

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