# double-opt-in/3.0.3/core/Compatibility.class.php

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

- Page: https://pluginprobe.com/plugins/double-opt-in/3.0.3/code/core/Compatibility.class.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/3.0.3/raw/core/Compatibility.class.php
- Modified: 2024-08-13T13:52:36+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/core/Compatibility.class.php#L10-L20`.

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn {
	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}

	/**
	 * Class Compatibility
	 */
	class Compatibility {
		/**
		 * @var array<string, string>
		 */
		private $components = array();

		/**
		 * @var CF7DoubleOptIn $Controller
		 */
		private $Controller;

		/**
		 * UI constructor.
		 *
		 * @param $slug
		 */
		public function __construct( $Controller ) {
			$this->Controller = $Controller;
			$this->load_components();

			add_action( 'after_setup_theme', function () {
				add_action( 'f12_cf7_doubleoptin_ui_after_load_compatibilities', array(
					$this,
					'registerComponents'
				), 10, 1 );
				do_action( 'f12_cf7_doubleoptin_ui_after_load_compatibilities', $this );
			} );
		}

		/**
		 * Loads the components for the current application.
		 *
		 * This method is responsible for loading the components for the current application.
		 * It retrieves the directories where the components are located using the `get_component_directories()`
		 * method and then iterates through each directory to load the components using the `load()` method.
		 *
		 * @return void
		 * @since 3.0.0
		 * @see   get_component_directories()
		 * @see   load()
		 */
		private function load_components() {
			$directories = $this->get_component_directories();

			foreach ( $directories as $directory ) {
				$this->load( $directory, 0 );
			}
		}

		/**
		 * Retrieves the component directories.
		 *
		 * This method allows developers to retrieve an array of component directories. These directories are used for
		 * displaying UI pages.
		 *
		 * @return array An array of component directories.
		 *
		 * @since 3.0.0
		 */
		private function get_component_directories() {
			/**
			 * Component Directories
			 *
			 * This filter allows developers to add custom ui directories which will be used to display ui pages.
			 *
			 * @param array $directories
			 *
			 * @since 3.0.0
			 */
			return apply_filters( 'f12_cf7_doubleoption_compatbility_get_component_directories', [ dirname( dirname( __FILE__ ) ) . '/compatibility' ] );
		}

		public function registerComponents( $Compatibility ) {
			foreach ( $this->components as $component ) {
				if ( isset( $component['name'] ) && isset( $component['path'] ) ) {
					require_once( $component['path'] );
					new $component['name']( $this->Controller );
				}
			}
		}

		private function addComponent( $name, $path ) {
			$this->components[] = array(
				'name' => $name,
				'path' => $path
			);
		}

		private function load( $directory, $lvl ) {
			if ( is_dir( $directory ) ) {
				$handle = opendir( $directory );

				if ( ! $handle ) {
					return;
				}

				while ( false !== ( $entry = readdir( $handle ) ) ) {
					if ( $entry != '.' && $entry != '..' ) {
						if ( is_dir( $directory . '/' . $entry ) && $lvl == 0 ) {
							$this->load( $directory . '/' . $entry, $lvl + 1 );
						} else {
							if ( preg_match( '!Controller([a-zA-Z_0-9]+)\.class\.php!', $entry, $matches ) ) {
								if ( isset( $matches[1] ) ) {
									$this->addComponent( '\\' . __NAMESPACE__ . '\Controller' . $matches[1], $directory . '/' . $entry );
								}
							}
						}
					}
				}
			}
		}
	}
}
```
