| 1 |
<?php |
| 2 |
|
| 3 |
use FernleafSystems\Wordpress\Plugin\Shield\Controller; |
| 4 |
use FernleafSystems\Wordpress\Services\Services; |
| 5 |
|
| 6 |
if ( !\defined( 'ABSPATH' ) ) { exit(); } |
| 7 |
|
| 8 |
/** @var string $rootFile */ |
| 9 |
global $oICWP_Wpsf; |
| 10 |
if ( isset( $oICWP_Wpsf ) || empty( $rootFile ) ) { |
| 11 |
return; |
| 12 |
} |
| 13 |
|
| 14 |
class ICWP_WPSF_Shield_Security { |
| 15 |
|
| 16 |
private static ?ICWP_WPSF_Shield_Security $oInstance = null; |
| 17 |
|
| 18 |
private Controller\Controller $con; |
| 19 |
|
| 20 |
private function __construct( Controller\Controller $controller ) { |
| 21 |
$this->con = $controller; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* @throws \Exception |
| 26 |
*/ |
| 27 |
public function start() { |
| 28 |
$this->con->boot(); |
| 29 |
} |
| 30 |
|
| 31 |
public function getController() :Controller\Controller { |
| 32 |
return Controller\Controller::GetInstance(); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* @throws \Exception |
| 37 |
*/ |
| 38 |
public static function GetInstance( ?Controller\Controller $con = null ) :\ICWP_WPSF_Shield_Security { |
| 39 |
if ( \is_null( self::$oInstance ) ) { |
| 40 |
if ( !$con instanceof Controller\Controller ) { |
| 41 |
throw new \Exception( 'Trying to create a Shield Plugin instance without a valid Controller' ); |
| 42 |
} |
| 43 |
self::$oInstance = new self( $con ); |
| 44 |
} |
| 45 |
return self::$oInstance; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
Services::GetInstance(); |
| 50 |
|
| 51 |
try { |
| 52 |
$oICWP_Wpsf_Controller = Controller\Controller::GetInstance( $rootFile ); |
| 53 |
$oICWP_Wpsf = ICWP_WPSF_Shield_Security::GetInstance( $oICWP_Wpsf_Controller ); |
| 54 |
$oICWP_Wpsf->start(); |
| 55 |
} |
| 56 |
catch ( Controller\Exceptions\VersionMismatchException $e ) { |
| 57 |
add_action( 'admin_notices', function () { |
| 58 |
echo sprintf( '<div class="notice error"><p>%s</p></div>', |
| 59 |
'Shield Security: There appears to be a configuration issue - please reinstall the Shield Security plugin.' ); |
| 60 |
} ); |
| 61 |
} |
| 62 |
catch ( Controller\Exceptions\PluginConfigInvalidException $e ) { |
| 63 |
add_action( 'admin_notices', function () use ( $e ) { |
| 64 |
echo sprintf( '<div class="notice error"><p>%s</p><p>%s</p></div>', |
| 65 |
'Shield Security: Could not load the plugin modules configuration. Please refresh and if the problem persists, please reinstall the Shield plugin.', |
| 66 |
$e->getMessage() |
| 67 |
); |
| 68 |
} ); |
| 69 |
} |
| 70 |
catch ( \Exception $e ) { |
| 71 |
error_log( 'Perhaps due to a failed upgrade, the Shield plugin failed to load certain component(s) - you should remove the plugin and reinstall.' ); |
| 72 |
error_log( $e->getMessage() ); |
| 73 |
} |