constants = SharedCore::container()->make(Constants::class); Hooks::addAction('plugins_loaded', self::class, 'init'); register_activation_hook($this->constants->getPluginFile(), [PluginManager::class, 'activate']); register_deactivation_hook($this->constants->getPluginFile(), [PluginManager::class, 'deactivate']); // Add plugin meta Hooks::addFilter( 'plugin_row_meta', PluginMeta::class, 'addPluginRowMeta', 10, 2 ); } /** * Initiate WpRollback when WordPress Initializes plugins. * * @since 3.0.0 */ public function init(): void { /** * Fires before the WpRollback core is initialized. * * @since 3.0.0 */ do_action('before_wpr_init'); // Ensure Constants is available if (null === $this->constants) { $this->constants = SharedCore::container()->make(Constants::class); } $this->setupLanguage(); $this->registerLibraries(); $this->loadServiceProviders(); // Initialize scripts after service providers are loaded $scripts = SharedCore::container()->make(PluginScripts::class); $scripts->initialize(); /** * Fire the action after WpRollback core loads. * * @since 3.0.0 * * @param self $instance Plugin class instance. * */ do_action('wpr_init', $this); } /** * This function is used to set up language for application. * * @since 3.0.0 */ protected function setupLanguage(): void { Language::load(); } /** * This function is used to load service providers. * * @since 3.0.0 */ protected function loadServiceProviders(): void { if ($this->providersLoaded) { return; } $providers = []; foreach ($this->serviceProviders as $serviceProvider) { if (! is_subclass_of($serviceProvider, ServiceProvider::class)) { throw new InvalidArgumentException( // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped "$serviceProvider class must implement the ServiceProvider interface" ); } /** @var ServiceProvider $serviceProvider */ $serviceProvider = new $serviceProvider(); $serviceProvider->register(); $providers[] = $serviceProvider; } foreach ($providers as $serviceProvider) { $serviceProvider->boot(); } $this->providersLoaded = true; } /** * Register third-party libraries. * * @since 3.0.0 */ protected function registerLibraries(): void { // No third-party libraries to register } /** * Get the Constants instance * * @since 3.0.0 * * @return Constants */ public function getConstants(): Constants { if (null === $this->constants) { $this->constants = SharedCore::container()->make(Constants::class); } return $this->constants; } }