# double-opt-in/3.1.0/OnActivation.php

Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification, version 3.1.0. 135 lines.

- Page: https://pluginprobe.com/plugins/double-opt-in/3.1.0/code/OnActivation.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/3.1.0/raw/OnActivation.php
- Modified: 2025-09-23T13:34:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/double-opt-in/3.1.0/code/OnActivation.php#L10-L20`.

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn;

use Forge12\Shared\Logger;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Create the table to store the opt ins.
 *
 * @return void
 */
function createTableOptIn() {
	global $wpdb;

	$logger = Logger::getInstance();

	$tableName   = 'f12_cf7_doubleoptin';
	$wpTableName = $wpdb->prefix . $tableName;

	$logger->info( 'Creating database table', [
		'plugin'     => 'double-opt-in',
		'table_name' => $wpTableName,
		'class'      => __CLASS__ ?? null,
		'method'     => __FUNCTION__,
	] );

	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

	$sql = "CREATE TABLE " . $wpTableName . " (
        id int(11) NOT NULL auto_increment, 
        cf_form_id int(11) NOT NULL, 
        doubleoptin int(2), 
        content LONGTEXT, 
        files LONGTEXT,
        hash VARCHAR(255),
        ipaddr_register varchar(255) NOT NULL DEFAULT '',
        ipaddr_confirmation varchar(255) NOT NULL DEFAULT '',
        ipaddr_optout varchar(255) NOT NULL DEFAULT '',
        createtime varchar(255) DEFAULT '', 
        updatetime varchar(255) DEFAULT '',
        optouttime varchar(255) DEFAULT '',
        category int(11),
        email varchar(255),
        form LONGTEXT,
        mail_optin LONGTEXT,
        PRIMARY KEY  (id)
    )";

	dbDelta( $sql );

	$logger->info( 'Database table created or updated', [
		'plugin'     => 'double-opt-in',
		'table_name' => $wpTableName,
		'class'      => __CLASS__ ?? null,
		'method'     => __FUNCTION__,
	] );
}


/**
 * Create the table for the categories
 *
 * @return void
 */
function createTableOptinCategories() {
	global $wpdb;

	$logger = Logger::getInstance();

	$tableName   = 'f12_cf7_doubleoptin_categories';
	$wpTableName = $wpdb->prefix . $tableName;

	$logger->info( 'Creating database table', [
		'plugin'     => 'double-opt-in',
		'table_name' => $wpTableName,
		'class'      => __CLASS__ ?? null,
		'method'     => __FUNCTION__,
	] );

	require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

	$sql = "CREATE TABLE " . $wpTableName . " (
        id int(11) NOT NULL auto_increment, 
        name varchar(255),
        createtime varchar(255) DEFAULT '', 
        updatetime varchar(255) DEFAULT '',
        PRIMARY KEY  (id)
    )";

	dbDelta( $sql );

	$logger->info( 'Database table created or updated', [
		'plugin'     => 'double-opt-in',
		'table_name' => $wpTableName,
		'class'      => __CLASS__ ?? null,
		'method'     => __FUNCTION__,
	] );
}


/**
 * On Activation create the custom table to store the required information
 * for the double opt in system.
 */
function onActivation() {
	$logger = Logger::getInstance();

	$logger->info( 'Plugin activation started', [
		'plugin' => 'double-opt-in',
		'class'  => __CLASS__ ?? null,
		'method' => __FUNCTION__,
	] );

	createTableOptin();
	$logger->debug( 'createTableOptin executed', [
		'plugin' => 'double-opt-in',
	] );

	createTableOptinCategories();
	$logger->debug( 'createTableOptinCategories executed', [
		'plugin' => 'double-opt-in',
	] );

	$logger->info( 'Plugin activation completed', [
		'plugin' => 'double-opt-in',
		'class'  => __CLASS__ ?? null,
		'method' => __FUNCTION__,
	] );
}

register_activation_hook( plugin_dir_path(__FILE__).'CF7DoubleOptIn.class.php', '\forge12\contactform7\CF7DoubleOptIn\onActivation' );
```
