renderer_factory = $renderer_factory; $this->access_control = $access_control; $this->api = $api; $this->activator = $activator; $this->settings = $settings; $this->router = $router; $this->hooks = $hooks; $this->changelog = $changelog; $this->menu = $menu; $this->cron_trigger = $cron_trigger; } function init() { $requirements_check_results = $this->checkRequirements(); if (!$requirements_check_results[RequirementsChecker::TEST_PDO_EXTENSION] || !$requirements_check_results[RequirementsChecker::TEST_VENDOR_SOURCE] ) { return; } // load translations $this->setupLocalizer(); try { $this->setupDB(); } catch (\Exception $e) { return WPNotice::displayError(Helpers::replaceLinkTags( __('Unable to connect to the database (the database is unable to open a file or folder), the connection is likely not configured correctly. Please read our [link] Knowledge Base article [/link] for steps how to resolve it.', 'mailpoet'), '//beta.docs.mailpoet.com/article/200-solving-database-connection-issues', array('target' => '_blank') )); } // activation function register_activation_hook( Env::$file, array( $this, 'runActivator' ) ); add_action('activated_plugin', array( new PluginActivatedHook(new DeferredAdminNotices), 'action' ), 10, 2); add_action('init', array( $this, 'preInitialize' ), 0); add_action('init', array( $this, 'initialize' )); add_action('admin_init', array( $this, 'setupPrivacyPolicy' )); add_action('wp_loaded', array( $this, 'postInitialize' )); add_action('admin_init', array( new DeferredAdminNotices, 'printAndClean' )); } function checkRequirements() { $requirements = new RequirementsChecker(); return $requirements->checkAllRequirements(); } function runActivator() { return $this->activator->activate(); } function setupDB() { $database = new Database(); $database->init(); } function preInitialize() { try { $this->renderer = $this->renderer_factory->getRenderer(); $this->setupWidget(); } catch (\Exception $e) { $this->handleFailedInitialization($e); } } function setupWidget() { register_widget('\MailPoet\Form\Widget'); } function initialize() { try { $this->maybeDbUpdate(); $this->setupInstaller(); $this->setupUpdater(); $this->setupCapabilities(); $this->menu->init(); $this->setupShortcodes(); $this->setupImages(); $this->setupPersonalDataExporters(); $this->setupPersonalDataErasers(); $this->changelog->init(); $this->setupCronTrigger(); $this->setupConflictResolver(); $this->setupPages(); $this->setupPermanentNotices(); $this->setupDeactivationSurvey(); do_action('mailpoet_initialized', MAILPOET_VERSION); } catch (\Exception $e) { return $this->handleFailedInitialization($e); } define(self::INITIALIZED, true); } function maybeDbUpdate() { try { $current_db_version = $this->settings->get('db_version'); } catch (\Exception $e) { $current_db_version = null; } // if current db version and plugin version differ if (version_compare($current_db_version, Env::$version) !== 0) { $this->runActivator(); } } function setupInstaller() { $installer = new Installer( Installer::PREMIUM_PLUGIN_SLUG ); $installer->init(); } function setupUpdater() { $slug = Installer::PREMIUM_PLUGIN_SLUG; $plugin_file = Installer::getPluginFile($slug); if (empty($plugin_file) || !defined('MAILPOET_PREMIUM_VERSION')) { return false; } $updater = new Updater( $plugin_file, $slug, MAILPOET_PREMIUM_VERSION ); $updater->init(); } function setupLocalizer() { $localizer = new Localizer(); $localizer->init(); } function setupCapabilities() { $caps = new Capabilities($this->renderer); $caps->init(); } function setupShortcodes() { $shortcodes = new Shortcodes(); $shortcodes->init(); } function setupImages() { add_image_size('mailpoet_newsletter_max', Env::NEWSLETTER_CONTENT_WIDTH); } function setupCronTrigger() { // setup cron trigger only outside of cli environment if (php_sapi_name() !== 'cli') { $this->cron_trigger->init(); } } function setupConflictResolver() { $conflict_resolver = new ConflictResolver(); $conflict_resolver->init(); } function postInitialize() { if (!defined(self::INITIALIZED)) return; try { $this->hooks->init(); $this->api->init(); $this->router->init(); $this->setupUserLocale(); } catch (\Exception $e) { $this->handleFailedInitialization($e); } } function setupUserLocale() { if (get_user_locale() === get_locale()) return; unload_textdomain(Env::$plugin_name); $localizer = new Localizer(); $localizer->init(); } function setupPages() { $pages = new \MailPoet\Settings\Pages(); $pages->init(); } function setupPrivacyPolicy() { $privacy_policy = new PrivacyPolicy(); $privacy_policy->init(); } function setupPersonalDataExporters() { $exporters = new PersonalDataExporters(); $exporters->init(); } function setupPersonalDataErasers() { $erasers = new PersonalDataErasers(); $erasers->init(); } function setupPermanentNotices() { $notices = new PermanentNotices(); $notices->init(); } function handleFailedInitialization($exception) { // check if we are able to add pages at this point if (function_exists('wp_get_current_user')) { Menu::addErrorPage($this->access_control); } return WPNotice::displayError($exception); } function setupDeactivationSurvey() { $survey = new DeactivationSurvey($this->renderer); $survey->init(); } }