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