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

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

- Page: https://pluginprobe.com/plugins/double-opt-in/3.0.3/code/OnActivation.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/3.0.3/raw/OnActivation.php
- Modified: 2024-10-08T06:33: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.0.3/code/OnActivation.php#L10-L20`.

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Create the table to store the opt ins.
 *
 * @return void
 */
function createTableOptIn() {
	global $wpdb;

	$tableName   = 'f12_cf7_doubleoptin';
	$wpTableName = $wpdb->prefix . $tableName;

	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 );
}

/**
 * Create the table for the categories
 *
 * @return void
 */
function createTableOptinCategories() {
	global $wpdb;

	$tableName   = 'f12_cf7_doubleoptin_categories';
	$wpTableName = $wpdb->prefix . $tableName;

	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 );
}

/**
 * On Activation create the custom table to store the required information
 * for the double opt in system.
 */
function onActivation() {
	createTableOptin();
	createTableOptinCategories();

	// Add cron
	if ( ! wp_next_scheduled( 'dailyOptinClear' ) ) {
		wp_schedule_event( time(), 'daily', 'dailyOptinClear' );
	}
}

register_activation_hook( plugin_dir_path(__FILE__).'CF7DoubleOptIn.class.php', '\forge12\contactform7\CF7DoubleOptIn\onActivation' );
```
