PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.5.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.5.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
← All changes | OnActivation.php +84 -15 3.1.0 → 5.5.0 View file →
@@ -46,8 +46,12 @@
46 46 category int(11),
47 47 email varchar(255),
48 48 form LONGTEXT,
49 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,
50 54 PRIMARY KEY (id)
51 55 )";
52 56
53 57 dbDelta( $sql );
@@ -105,31 +109,96 @@
105 109 /**
106 110 * On Activation create the custom table to store the required information
107 111 * for the double opt in system.
108 112 */
109 -function onActivation() {
113 +function onActivation( $network_wide = false ) {
110 114 $logger = Logger::getInstance();
111 115
112 116 $logger->info( 'Plugin activation started', [
113 - 'plugin' => 'double-opt-in',
114 - 'class' => __CLASS__ ?? null,
115 - 'method' => __FUNCTION__,
117 + 'plugin' => 'double-opt-in',
118 + 'network_wide' => $network_wide,
119 + 'class' => __CLASS__ ?? null,
120 + 'method' => __FUNCTION__,
116 121 ] );
117 122
118 - createTableOptin();
119 - $logger->debug( 'createTableOptin executed', [
120 - 'plugin' => 'double-opt-in',
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 + restore_current_blog();
131 + }
132 + } else {
133 + createTableOptin();
134 + createTableOptinCategories();
135 + createTableAuditLog();
136 + }
137 +
138 + $logger->info( 'Plugin activation completed', [
139 + 'plugin' => 'double-opt-in',
140 + 'network_wide' => $network_wide,
141 + 'class' => __CLASS__ ?? null,
142 + 'method' => __FUNCTION__,
121 143 ] );
144 +}
122 145
123 - createTableOptinCategories();
124 - $logger->debug( 'createTableOptinCategories executed', [
125 - 'plugin' => 'double-opt-in',
146 +/**
147 + * Create the table for the audit log.
148 + *
149 + * @since 4.2.0
150 + * @return void
151 + */
152 +function createTableAuditLog() {
153 + global $wpdb;
154 +
155 + $logger = Logger::getInstance();
156 +
157 + $tableName = 'f12_cf7_doubleoptin_audit_log';
158 + $wpTableName = $wpdb->prefix . $tableName;
159 +
160 + $logger->info( 'Creating audit log table', [
161 + 'plugin' => 'double-opt-in',
162 + 'table_name' => $wpTableName,
163 + 'method' => __FUNCTION__,
126 164 ] );
127 165
128 - $logger->info( 'Plugin activation completed', [
129 - 'plugin' => 'double-opt-in',
130 - 'class' => __CLASS__ ?? null,
131 - 'method' => __FUNCTION__,
166 + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
167 +
168 + $sql = "CREATE TABLE " . $wpTableName . " (
169 + id bigint(20) unsigned NOT NULL auto_increment,
170 + event_type varchar(50) NOT NULL,
171 + severity varchar(20) NOT NULL DEFAULT 'info',
172 + message text NOT NULL,
173 + user_id bigint(20) unsigned DEFAULT NULL,
174 + details longtext DEFAULT NULL,
175 + created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
176 + PRIMARY KEY (id),
177 + KEY idx_type (event_type),
178 + KEY idx_severity (severity),
179 + KEY idx_created (created_at)
180 + )";
181 +
182 + dbDelta( $sql );
183 +
184 + $logger->info( 'Audit log table created or updated', [
185 + 'plugin' => 'double-opt-in',
186 + 'table_name' => $wpTableName,
187 + 'method' => __FUNCTION__,
132 188 ] );
133 189 }
134 190
135 -register_activation_hook( plugin_dir_path(__FILE__).'CF7DoubleOptIn.class.php', '\forge12\contactform7\CF7DoubleOptIn\onActivation' );
191 +register_activation_hook( plugin_dir_path(__FILE__).'CF7DoubleOptIn.class.php', '\forge12\contactform7\CF7DoubleOptIn\onActivation' );
192 +
193 +add_action( 'wp_initialize_site', function ( $new_site ) {
194 + if ( ! is_plugin_active_for_network(
195 + plugin_basename( __DIR__ . '/CF7DoubleOptIn.class.php' )
196 + ) ) {
197 + return;
198 + }
199 + switch_to_blog( $new_site->blog_id );
200 + createTableOptin();
201 + createTableOptinCategories();
202 + createTableAuditLog();
203 + restore_current_blog();
204 +}, 900 );