| 1 |
<?php |
| 2 |
|
| 3 |
namespace AgeGate\App; |
| 4 |
|
| 5 |
use AgeGate\Common\Content; |
| 6 |
use AgeGate\Common\Settings; |
| 7 |
use AgeGate\Integration\Discover; |
| 8 |
use AgeGate\Controller\JsController; |
| 9 |
use AgeGate\Controller\StandardController; |
| 10 |
|
| 11 |
class AgeGate |
| 12 |
{ |
| 13 |
protected static $content; |
| 14 |
|
| 15 |
public function __construct() |
| 16 |
{ |
| 17 |
add_action('wp', [$this, 'init'], PHP_INT_MAX); |
| 18 |
} |
| 19 |
|
| 20 |
public function init() |
| 21 |
{ |
| 22 |
if (is_admin()) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
new Discover(); |
| 27 |
|
| 28 |
$settings = Settings::getInstance(); |
| 29 |
|
| 30 |
do_action('age_gate/settings', $settings); |
| 31 |
|
| 32 |
if ($settings->disableAgeGate) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
$content = new Content(); |
| 37 |
self::$content = apply_filters('age_gate/init/content', $content); |
| 38 |
|
| 39 |
if (!is_a(self::$content, 'AgeGate\\Common\\Content')) { |
| 40 |
_doing_it_wrong( 'age_gate/init/content', 'Must return instance of AgeGate\\Common\\Content', '3.4.0'); |
| 41 |
self::$content = $content; |
| 42 |
} |
| 43 |
|
| 44 |
if ($settings->method === 'js') { |
| 45 |
new JsController(self::$content); |
| 46 |
} else { |
| 47 |
new StandardController(self::$content); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
public static function getContent() |
| 52 |
{ |
| 53 |
return self::$content; |
| 54 |
} |
| 55 |
} |
| 56 |
|