log_repository = $log_repository; $this->register_builtin_modules(); } /** * Fire the extension-registration hook so built-in add-ons and marketplace * extensions (e.g. NoorSMTP Pro) can self-register their modules. * * Deliberately NOT called from the constructor: the free plugin boots on * `plugins_loaded` (default priority), and an add-on plugin registering * its own `plugins_loaded` listener at a later priority would otherwise * miss this action entirely. Called instead from Plugin::boot() on `init`, * after every active plugin has had a chance to hook `plugins_loaded`. * * @return void */ public function discover_extensions() { /** * Fires so marketplace extensions can self-register. * * Callback signature: function( ModuleManager $manager ). * * @since 1.0.0 */ do_action( 'noorsmtp_register_extension', $this ); } /** * Register the modules shipped with core. * * @return void */ private function register_builtin_modules() { $this->register( new SmtpModule() ); $this->register( new GmailApiModule() ); } /** * Register a module instance. * * @param ModuleInterface $module Module instance. * @return void */ public function register( ModuleInterface $module ) { $this->modules[ $module->slug() ] = $module; } /** * Get all registered modules. * * @return ModuleInterface[] */ public function all() { return $this->modules; } /** * Get a module by slug. * * @param string $slug Module slug. * @return ModuleInterface|null */ public function get( $slug ) { return isset( $this->modules[ $slug ] ) ? $this->modules[ $slug ] : null; } /** * Get the slug of the module chosen as the active mailer. * * @return string */ public function active_mailer_slug() { $settings = get_option( 'noorsmtp_settings', array() ); $slug = isset( $settings['mailer'] ) ? $settings['mailer'] : ''; /** * Filter the active mailer slug. * * @since 1.2.0 * @param string $slug Active mailer slug. */ return (string) apply_filters( 'noorsmtp_active_mailer_slug', $slug ); } /** * Boot every module that is currently active/selected. * * @return void */ public function boot_active_modules() { foreach ( $this->modules as $module ) { $module->boot(); } } /** * Get the log repository. * * @return LogRepository */ public function log_repository() { return $this->log_repository; } }