| 1 |
<?php |
| 2 |
/** |
| 3 |
* Collects feature modules and boots each eligible one. |
| 4 |
* |
| 5 |
* @package Import_Export_Menu |
| 6 |
* @since 2.2.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
declare(strict_types=1); |
| 10 |
|
| 11 |
namespace ImportExportMenu\Modules; |
| 12 |
|
| 13 |
use ImportExportMenu\Edition; |
| 14 |
|
| 15 |
defined( 'ABSPATH' ) || exit; |
| 16 |
|
| 17 |
/** |
| 18 |
* Single entry point that turns every registered module on. |
| 19 |
* |
| 20 |
* Modules are gathered through the `import_export_menu_modules_register` filter so this |
| 21 |
* plugin and a separate Pro plugin can both contribute without touching each |
| 22 |
* other's code. Pro-tier modules stay dormant until the Pro edition is |
| 23 |
* unlocked, so a registered-but-locked module never runs. |
| 24 |
* |
| 25 |
* Collection is deferred to `plugins_loaded` so a Pro plugin loaded after this |
| 26 |
* one still gets a chance to register its modules first. |
| 27 |
* |
| 28 |
* @since 2.2.0 |
| 29 |
*/ |
| 30 |
final class ModuleLoader { |
| 31 |
|
| 32 |
/** |
| 33 |
* Defer module collection until every plugin has registered its modules. |
| 34 |
*/ |
| 35 |
public function register_hooks(): void { |
| 36 |
add_action( 'plugins_loaded', array( $this, 'boot' ) ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Register the hooks of every eligible module. |
| 41 |
*/ |
| 42 |
public function boot(): void { |
| 43 |
/** |
| 44 |
* Filters the feature modules to boot. |
| 45 |
* |
| 46 |
* A separate Pro plugin hooks this to register its own modules without |
| 47 |
* modifying this plugin. Each entry must implement {@see ModuleInterface}. |
| 48 |
* |
| 49 |
* @since 2.2.0 |
| 50 |
* |
| 51 |
* @param ModuleInterface[] $modules Module instances to register. |
| 52 |
*/ |
| 53 |
$modules = apply_filters( 'import_export_menu_modules_register', array() ); |
| 54 |
|
| 55 |
foreach ( $modules as $module ) { |
| 56 |
if ( ModuleInterface::TIER_PRO === $module->tier() && ! Edition::is_pro_unlocked() ) { |
| 57 |
continue; |
| 58 |
} |
| 59 |
$module->register_hooks(); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|