*/ private array $modules = array(); /** * Collect and boot all modules. * * @return void */ public function boot(): void { $modules = $this->built_in_modules(); /** * Filters the list of modules to boot. * * Pro and the Woo Add-on use this to register their modules. * * @since 2.0.0 * * @param ModuleInterface[] $modules Modules to boot. */ $modules = apply_filters( 'aiou_register_modules', $modules ); $settings = aiou()->settings(); foreach ( $modules as $module ) { if ( ! $module instanceof ModuleInterface ) { continue; } $id = $module->get_id(); if ( isset( $this->modules[ $id ] ) ) { continue; } $this->modules[ $id ] = $module; $settings->set_owner( self::owner_of( $module ) ); $module->register(); } $settings->set_owner( 'free' ); } /** * Which plugin a module belongs to, read from its namespace: the part * after `WordTenance\AllInOneUtilities` -- nothing for Free itself, then * e.g. `Pro`, `Woo`, `Tools` -- lowercased. Generic on purpose, so Free * never has to know which add-ons exist. Modules from any other * namespace count as 'external'. * * @param ModuleInterface $module Module. * @return string */ private static function owner_of( ModuleInterface $module ): string { $prefix = 'WordTenance\\AllInOneUtilities'; $class = get_class( $module ); if ( 0 !== strpos( $class, $prefix ) ) { $owner = 'external'; } else { // Free's own classes continue with `\Modules\...`; an add-on's // with its product name, e.g. `Pro\Modules\...`. $rest = substr( $class, strlen( $prefix ) ); $owner = '' === $rest || '\\' === $rest[0] ? 'free' : strtolower( (string) strtok( $rest, '\\' ) ); } /** * Filters which plugin a module's settings are attributed to. * * @param string $owner Owner key, e.g. 'free', 'pro', 'woo', 'tools'. * @param ModuleInterface $module The module. */ return (string) apply_filters( 'aiou_module_owner', $owner, $module ); } /** * Built-in (Free) modules. * * EmailLogModule must come after EmailSettingsModule: it adds a section * to the 'emails' tab that module registers, and * `SettingsRegistry::add_section()` silently no-ops if its tab doesn't * exist yet. DisableAuthorPagesModule, DisableFeedsModule and RandomContentModule * must likewise come after DisableFeaturesModule, which registers the * 'performance' tab they each add their own section to. LoginLogoModule * no longer depends on FeaturedImageModule: it moved to the 'login' tab, which both it and * LoginPageModule register (first wins). RequireFeaturedImageModule must * come after FeaturedImageModule, which registers the 'media' tab it * adds its section to (and reuses its `PostTypes` helper); * SvgUploadsModule adds a section to that tab too. PostClonerModule * registers the 'content' tab that Pro's content features add to. * ShowIdsModule registers its own new 'admin' tab, so it has no * ordering dependency on the others; AdminCustomizationModule adds its * sections to that tab, so it must come after it. ClassicEditorModule, * UpdateControlModule, and AccessibilityModule each add their own * section to the 'performance' tab too, so they must also come after * DisableFeaturesModule. CustomCodeModule registers its own new * 'custom_code' tab, so it has no ordering dependency either, and so * does CountryStatesModule ('woocommerce', only while WooCommerce is * active). * UserManagementModule adds its own section to the 'users' tab that * UsernameUpdaterModule registers, so it must come after that one. * SecurityModule registers the 'security' tab, which * DisableFeaturesModule (Hardening) and DisableAuthorPagesModule add * their sections to, so it must come before both. DisableCommentsModule * adds a section to the 'performance' tab, so it follows * DisableFeaturesModule. * * @return ModuleInterface[] */ private function built_in_modules(): array { return array( new UsernameUpdaterModule(), new FeaturedImageModule(), new LoginPageModule(), new LoginLogoModule(), new SecurityModule(), new RequireFeaturedImageModule(), new SvgUploadsModule(), new ShowIdsModule(), new AdminCustomizationModule(), new UserRolesModule(), new DisableFeaturesModule(), new DisableCommentsModule(), new UserAvatarModule(), new UserManagementModule(), new UserSwitchingModule(), new EmailSettingsModule(), new EmailLogModule(), new DatabaseCleanupModule(), new PostClonerModule(), new DuplicatePostsModule(), new DuplicateMenuModule(), new DisableAuthorPagesModule(), new DisableFeedsModule(), new RandomContentModule(), new ClassicEditorModule(), new UpdateControlModule(), new AccessibilityModule(), new CustomCodeModule(), new CountryStatesModule(), ); } /** * Get a booted module by id. * * @param string $id Module id. * @return ModuleInterface|null */ public function get( string $id ): ?ModuleInterface { return $this->modules[ $id ] ?? null; } /** * All booted modules. * * @return array */ public function all(): array { return $this->modules; } }