| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if(!defined('ABSPATH')){ |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Class Compatibility |
| 10 |
*/ |
| 11 |
class Compatibility |
| 12 |
{ |
| 13 |
/** |
| 14 |
* @var array<string, string> |
| 15 |
*/ |
| 16 |
private $components = array(); |
| 17 |
|
| 18 |
/** |
| 19 |
* UI constructor. |
| 20 |
* @param $slug |
| 21 |
*/ |
| 22 |
public function __construct() |
| 23 |
{ |
| 24 |
$this->load(dirname(dirname(__FILE__)) . '/compatibility', 0); |
| 25 |
|
| 26 |
add_action('after_setup_theme', function(){ |
| 27 |
add_action('f12_cf7_doubleoptin_ui_after_load_compatibilities', array($this, 'registerComponents'), 10, 1); |
| 28 |
do_action('f12_cf7_doubleoptin_ui_after_load_compatibilities', $this); |
| 29 |
}); |
| 30 |
} |
| 31 |
|
| 32 |
public function registerComponents($Compatibility) |
| 33 |
{ |
| 34 |
foreach ($this->components as $component) { |
| 35 |
if (isset($component['name']) && isset($component['path'])) { |
| 36 |
require_once($component['path']); |
| 37 |
new $component['name'](); |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
private function addComponent($name, $path) |
| 43 |
{ |
| 44 |
$this->components[] = array( |
| 45 |
'name' => $name, |
| 46 |
'path' => $path |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
private function load($directory, $lvl) |
| 51 |
{ |
| 52 |
if (is_dir($directory)) { |
| 53 |
$handle = opendir($directory); |
| 54 |
|
| 55 |
if (!$handle) { |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
while (false !== ($entry = readdir($handle))) { |
| 60 |
if ($entry != '.' && $entry != '..') { |
| 61 |
if (is_dir($directory . '/' . $entry) && $lvl == 0) { |
| 62 |
$this->load($directory . '/' . $entry, $lvl + 1); |
| 63 |
} else { |
| 64 |
if (preg_match('!Controller([a-zA-Z_0-9]+)\.class\.php!', $entry, $matches)) { |
| 65 |
if (isset($matches[1])) { |
| 66 |
$this->addComponent('\\'.__NAMESPACE__.'\Controller' . $matches[1], $directory . '/' . $entry); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
} |