# double-opt-in/3.0.3/CF7DoubleOptIn.class.php

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

- Page: https://pluginprobe.com/plugins/double-opt-in/3.0.3/code/CF7DoubleOptIn.class.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/3.0.3/raw/CF7DoubleOptIn.class.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/CF7DoubleOptIn.class.php#L10-L20`.

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn {
	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}

	/**
	 * Plugin Name: Double Opt-In (Contact Form 7, Avada) - GDPR Ready
	 * Plugin URI: https://www.forge12.com/blog/so-verwendest-du-das-double-opt-in-fuer-contact-form-7/
	 * Description: This plugin allows you to add a double OptIn System to your Contact Form 7 & Avada Forms.
	 * Text Domain: double-opt-in
	 * Domain Path: /languages
	 * Version: 3.0.3
	 * Author: Forge12 Interactive GmbH
	 * Author URI: https://www.forge12.com
	 */
	define( 'FORGE12_OPTIN_VERSION', '3.0.3' );
	define( 'FORGE12_OPTIN_SLUG', 'f12-cf7-doubleoptin' );
	define( 'FORGE12_OPTIN_BASENAME', plugin_basename( __FILE__ ) );


	/**
	 * Dependencies
	 */
	require_once( 'core/BaseController.class.php' );

	require_once( 'OnActivation.php' );
	require_once( 'OnDeactivation.php' );
	require_once( 'OnUpdate.php' );
	require_once( 'compatibility/OptInFrontend.class.php' );

	require_once( 'core/Messages.class.php' );
	require_once( 'core/TemplateHandler.class.php' );
	require_once( 'core/IPHelper.class.php' );
	require_once( 'core/SanitizeHelper.class.php' );
	require_once( 'core/Ajax.class.php' );
	require_once( 'core/Compatibility.class.php' );
	require_once( 'core/CleanUp.class.php' );
	require_once( 'core/HTMLSelect.class.php' );
	require_once( 'core/UI.class.php' );
	require_once( 'core/UIPage.class.php' );
	require_once( 'core/UIPageForm.class.php' );
	require_once( 'core/OptIn.class.php' );
	require_once( 'core/OptInLimitFilter.class.php' );
	require_once( 'core/OptInSearchFilter.class.php' );
	require_once( 'core/Category.class.php' );
	require_once( 'core/CategoryOptions.class.php' );
	require_once( 'core/Pagination.class.php' );
	require_once( 'core/Support.class.php' );

	/**
	 * Class CF7DoubleOptIn
	 * Controller for the Custom Links.
	 *
	 * @package forge12\contactform7
	 */
	class CF7DoubleOptIn {
		/**
		 * @var CF7DoubleOptIn|Null
		 */
		private static $_instance = null;

		/**
		 * @var TemplateHandler|null
		 */
		private $TemplateHandler = null;

		/**
		 * Get the singleton instance of CF7DoubleOptIn.
		 *
		 * @return CF7DoubleOptIn The singleton instance.
		 */
		public static function getInstance() {
			if ( self::$_instance == null ) {
				self::$_instance = new self();
			}

			return self::$_instance;
		}

		/**
		 * Return a list containing the array with all data stored within the form
		 *
		 * @param int           $postID
		 *
		 * @formatter:off
		 *
		 * @return {
		 *      @type int       $enable     The Status of the OptIn, either 1 for enabled or 0 for disabled. Default: 0
		 *      @type string    $sender     The E-Mail of the sender of the optIn mail
		 *      @type string    $subject    The Subject of the OptIn Mail
		 *      @type string    $body       The Content of the OptIn Mail
		 *      @type string    $recipient  The Field that contains the E-Mail of the Recipient.
		 *      @type int       $page       The Post ID of the confirmation page. Default: -1
		 *      @type string    $conditions Additional condition to dynamically enable / disable the optin.
		 *                                  Default: disabled
		 *      @type string    $template   The Template used for the OptIn Mail
		 *      @type int       $category   The Category the OptIns will be assigned to.
		 * }
		 * @formatter:on
		 */
		public function getParameter( $postID ) {

			$data = [
				'enable'          => 0,
				'sender'          => get_bloginfo( 'admin_email' ),
				'sender_name'     => '',
				'subject'         => '',
				'body'            => '',
				'recipient'       => '',
				'page'            => - 1,
				'conditions'      => 'disabled',
				'template'        => '',
				'category'        => 0,
			];

			/**
			 * DOI Parameter
			 *
			 * Filters the parameter for the DOI. This hook allows developers
			 * to alter DOI fields.
			 *
			 * @param array $data Additional Fields
			 *
			 * @since 1.0.0
			 */
			$data = apply_filters( 'f12_cf7_doubleoptin_get_parameter', $data );

			if ( ! $postID ) {
				return $data;
			}

			$options = get_post_meta( $postID, 'f12-cf7-doubleoptin', true );

			if ( ! $options ) {
				return $data;
			}

			return array_merge( $data, $options );
		}

		/**
		 * Private constructor to prevent direct instantiation.
		 */
		private function __construct() {
			load_plugin_textdomain( 'double-opt-in', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
			/**
			 * DOI INIT
			 *
			 * Run custom actions after the DOI has been initialized
			 *
			 * @param CF7DoubleOptIn $this
			 *
			 * @since 3.0.0
			 */
			do_action( 'f12_cf7_doubleoptin_init', $this );


			$this->TemplateHandler = TemplateHandler::getInstance();

			$UI = new UI( $this->TemplateHandler, FORGE12_OPTIN_SLUG, 'Forge12 Double Opt-In', 'manage_options' );

			add_action( 'after_setup_theme', array( $this, 'init' ) );

			$Compatibility = new Compatibility( $this );
			$CleanUp       = new CleanUp();

			// Pagination
			Pagination::getInstance();

			// initialize filter
			CategoryOptions::getInstance();
			OptInLimitFilter::getInstance();
			OptInSearchFilter::getInstance();

			// Support
			Support::getInstance();
		}

		/**
		 * Retrieve the template handler instance.
		 *
		 * @return TemplateHandler The template handler instance.
		 */
		public function get_template_handler() {
			return $this->TemplateHandler;
		}

		/**
		 * @private WordPress Hook
		 */
		public function init() {
			do_action( 'f12_cf7_doubleoptin_register_implementations' );
		}

		/**
		 * Return the settings for the optin.
		 *
		 * @param string        $single                     The Key of the setting to return only the required setting
		 *
		 * @formatter:off
		 * @return {
		 *     // Returns the Settings for the DOI
		 *
		 *      @type string    $optout_subject             The Subject for the OptOut Mail
		 *      @type string    $optout_body                The Content for the OptOut Mail
		 *      @type int       $optout_page                The Post ID for the OptOut Page
		 *      @type int       $support                    Defines if the Support link will be added to the footer
		 *      @type int       $delete                     An integer from 1 to 30
		 *      @type int       $delete_unconfirmed         An integer from 1 to 30
		 *      @type string    $delete_period              The time period, either months, days, years
		 *      @type string    $delete_unconfirmed_period  The time period, either months, days, years
		 * }
		 * @formatter:on
		 */
		public function getSettings( $single = '', $container = null ) {
			$default = array();

			$default = apply_filters( 'f12_cf7_doubleoptin_settings', $default );

			$settings = get_option( 'f12-doi-settings' );

			if ( ! is_array( $settings ) ) {
				$settings = array();
			}

			foreach ( $default as $key => $data ) {
				if ( isset( $settings[ $key ] ) ) {
					if ( is_array( $default[ $key ] ) ) {
						$default[ $key ] = array_merge( $default[ $key ], $settings[ $key ] );
					} else {
						$default[ $key ] = $settings[ $key ];
					}
				}
			}

			$settings = $default;

			if ( ! empty( $single ) ) {
				if ( $container != null ) {
					if ( isset( $settings[ $container ] ) && isset( $settings[ $container ][ $single ] ) ) {
						$settings = $settings[ $container ][ $single ];
					}
				}
			} else {
				if ( isset( $settings[ $single ] ) ) {
					$settings = $settings[ $single ];
				}
			}

			return $settings;
		}
	}


	CF7DoubleOptIn::getInstance();

}
```
