| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\ConnectManager; |
| 4 |
|
| 5 |
use ImageOptimization; |
| 6 |
use ImageOptimization\Classes\Module_Base; |
| 7 |
|
| 8 |
use ImageOptimization\Modules\ConnectManager\{ |
| 9 |
Classes\Connect_Runner, |
| 10 |
Components\Legacy_Connect, |
| 11 |
Components\Connect, |
| 12 |
}; |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; // Exit if accessed directly |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Class Module |
| 20 |
*/ |
| 21 |
class Module extends Module_Base { |
| 22 |
|
| 23 |
/** |
| 24 |
* Connect instance |
| 25 |
*/ |
| 26 |
public $connect_instance; |
| 27 |
|
| 28 |
/** |
| 29 |
* Get module name. |
| 30 |
* Retrieve the module name. |
| 31 |
* @access public |
| 32 |
* @return string Module name. |
| 33 |
*/ |
| 34 |
public function get_name() { |
| 35 |
return 'connect-manager'; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* component_list |
| 40 |
* @return string[] |
| 41 |
*/ |
| 42 |
public static function component_list(): array { |
| 43 |
return [ |
| 44 |
'Legacy_Connect', |
| 45 |
'Connect', |
| 46 |
]; |
| 47 |
} |
| 48 |
|
| 49 |
public function __construct() { |
| 50 |
// Register components. |
| 51 |
$this->register_components(); |
| 52 |
// Load Connect Manager. |
| 53 |
add_action( 'plugins_loaded', [ $this, 'load_connect_manager' ] ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Load Connect Manager |
| 58 |
* |
| 59 |
* Load the correct version of Connect Manager based on whether |
| 60 |
* the user is already connected using legacy version or not. |
| 61 |
* |
| 62 |
* @return void |
| 63 |
*/ |
| 64 |
public function load_connect_manager() { |
| 65 |
if ( ImageOptimization\Modules\Connect\Module::is_active() ) { |
| 66 |
$this->connect_instance = new Connect_Runner( new Connect() ); |
| 67 |
} else { |
| 68 |
$this->connect_instance = new Connect_Runner( new Legacy_Connect() ); |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|