<?php namespace MailPoet\Config; if (!defined('ABSPATH')) exit; use MailPoet\Services\Bridge; use MailPoet\Services\Release\API; use MailPoet\Settings\SettingsController; use MailPoet\Util\License\License; use MailPoet\WP\Functions as WPFunctions; class Installer { const PREMIUM_PLUGIN_SLUG = 'mailpoet-premium'; private $slug; /** @var SettingsController */ private $settings; public function __construct( $slug ) { $this->slug = $slug; $this->settings = SettingsController::getInstance(); } public function init() { WPFunctions::get()->addFilter('plugins_api', [$this, 'getPluginInformation'], 10, 3); } public function getPluginInformation($data, $action = '', $args = null) { if ($action === 'plugin_information' && isset($args->slug) && $args->slug === $this->slug ) { $data = $this->retrievePluginInformation(); } return $data; } public static function getPremiumStatus() { $slug = self::PREMIUM_PLUGIN_SLUG; $premiumPluginActive = License::getLicense(); $premiumPluginInstalled = $premiumPluginActive || self::isPluginInstalled($slug); $premiumPluginInitialized = defined('MAILPOET_PREMIUM_INITIALIZED') && MAILPOET_PREMIUM_INITIALIZED; $installer = new Installer(self::PREMIUM_PLUGIN_SLUG); $pluginInformation = $installer->retrievePluginInformation(); return [ 'premium_plugin_active' => $premiumPluginActive, 'premium_plugin_installed' => $premiumPluginInstalled, 'premium_plugin_initialized' => $premiumPluginInitialized, 'premium_plugin_info' => $pluginInformation, ]; } public static function isPluginInstalled($slug) { $installedPlugin = self::getInstalledPlugin($slug); return !empty($installedPlugin); } private static function getInstalledPlugin($slug) { $installedPlugin = []; if (is_dir(WP_PLUGIN_DIR . '/' . $slug)) { $installedPlugin = WPFunctions::get()->getPlugins('/' . $slug); } return $installedPlugin; } public static function getPluginFile($slug) { $pluginFile = false; $installedPlugin = self::getInstalledPlugin($slug); if (!empty($installedPlugin)) { $pluginFile = $slug . '/' . key($installedPlugin); } return $pluginFile; } public function retrievePluginInformation() { $key = $this->settings->get(Bridge::PREMIUM_KEY_SETTING_NAME); $api = new API($key); $info = $api->getPluginInformation($this->slug); $info = $this->formatInformation($info); return $info; } private function formatInformation($info) { // cast sections object to array for WP to understand if (isset($info->sections)) { $info->sections = (array)$info->sections; } return $info; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
PopulatorData | Folder | 0700 |
|
|
AccessControl.php | File | 3.23 KB | 0644 |
|
Activator.php | File | 2.22 KB | 0644 |
|
AssetsLoader.php | File | 801 B | 0644 |
|
Capabilities.php | File | 2.8 KB | 0644 |
|
Changelog.php | File | 3.9 KB | 0644 |
|
Database.php | File | 2.78 KB | 0644 |
|
DatabaseInitializer.php | File | 601 B | 0644 |
|
DeferredAdminNotices.php | File | 1.07 KB | 0644 |
|
Env.php | File | 3.93 KB | 0644 |
|
Hooks.php | File | 10.32 KB | 0644 |
|
HooksWooCommerce.php | File | 3.97 KB | 0644 |
|
Initializer.php | File | 9.92 KB | 0644 |
|
Installer.php | File | 2.69 KB | 0644 |
|
Localizer.php | File | 1.15 KB | 0644 |
|
MP2Migrator.php | File | 35.34 KB | 0644 |
|
Menu.php | File | 14.04 KB | 0644 |
|
Migrator.php | File | 25.73 KB | 0644 |
|
PersonalDataErasers.php | File | 622 B | 0644 |
|
PersonalDataExporters.php | File | 2.64 KB | 0644 |
|
PluginActivatedHook.php | File | 682 B | 0644 |
|
Populator.php | File | 29.67 KB | 0644 |
|
PrivacyPolicy.php | File | 3.37 KB | 0644 |
|
Renderer.php | File | 3.95 KB | 0644 |
|
RendererFactory.php | File | 474 B | 0644 |
|
RequirementsChecker.php | File | 4.3 KB | 0644 |
|
Router.php | File | 846 B | 0644 |
|
ServicesChecker.php | File | 4.93 KB | 0644 |
|
Shortcodes.php | File | 6.22 KB | 0644 |
|
Updater.php | File | 1.71 KB | 0644 |
|
index.php | File | 0 B | 0644 |
|